none
Excluding Items from Combo Box

    Question

  • Pretty basic question regarding making querys that would filter combo box selection :)

    How to exclude items from combo box that have already been selected once?

    In a simple example, let's assign employees to tasks (A task can have many employees). How to disable the same employee to appear in combo box when he is already selected for a task?

    On first picture I already selected Ana and Ivan for second task, but I can still keep selecting them.

    What I need is that combo box selection is filtered and does not show Ana and Ivan because they are already assigned to this task.

    I tried with some querys but without complete success. Please help! Thanks!


    Thursday, January 26, 2012 1:41 PM

Answers

  • This is not an issue. Selecting the AutoCompleteBox of the employee in the properties on the right you can select this query as source. Select this QryEmployees instead of Auto.

    The problem is that this query will be up to date only after every refresh. I mean in the example presented adding Marko to the task will not (and there is no way to do this with standard LS methods) be removed from the list of available employees. Only, after saving and refreshing you will have coherent interface again.

    About your query:

    Create a query on Employees (e.g. QryEmployees).

    Add a parameter int taskId required and then write 

    partial void QryEmployees_PreProcessQuery(int taskId){

      query = query.Where(e=>!e.Reserved && e.EmployeesOnTasks.FirstOrDefault(et=>et.Task.Id.Equals(taskId)) == null);

    }

    When you add this query to your screen, on the left select taskId parameter of qryEmployees and on the right in properties bind this parameter to Tasks.SelectetItem.Id.

    That's it.


    1+1 = 3 for large values of 1




    Sunday, March 11, 2012 10:00 AM

All replies

  • Have a look at these two articles, & see if they give you something to work with. You'd just need to modify the technique to suit your situation.

    Nested AutoCompleteBox For Data Entry

    Nested AutoCompleteBox for data entry Part 2


    Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands
     
    If you find a reply helpful, please click "Vote as Helpful", if a reply answers your question, please click "Mark as Answer"
     
    By doing this you'll help people find answers faster.
    Thursday, January 26, 2012 1:55 PM
    Moderator
  • I understand the logic in these examples, these are simple "one to many" nested tables:

    Country-Town-Customer

    (Some customers are in Oxford which is in Oxfordshire)

     

    In my case, I think it is a bit more complex because same employee can be present in many tasks.

    I have many-to-many relationship between tasks and employees.

    (First task is done by Ana and Marko, Second task is done by Ana, Marko and Ivan, Third task is done just by Ana)

    Is there some similar example to this one?

    Does this make sense? (sorry if I missed something big here, I am really a begginer regarding databases in general!)

    Thursday, January 26, 2012 2:21 PM
  • hi!

    did you check new many to many control?

    http://code.msdn.microsoft.com/Many-to-Many-Control-for-52cd8c6c

    at the end of article you have little "advanced" scenario..

    maybe you can find it useful (except it have checkboxes)..

    Kivito

    (btw. imas @ spasol.wordpress.com dobrih clanaka o Lightswitchu opcenito)


    Nobody expects the Spanish Inquisition! (M.P.F.C.)
    Thursday, January 26, 2012 8:23 PM
  • That's why I said "You'd just need to modify the technique to suit your situation". :-)
    Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands
     
    If you find a reply helpful, please click "Vote as Helpful", if a reply answers your question, please click "Mark as Answer"
     
    By doing this you'll help people find answers faster.
    Friday, January 27, 2012 4:38 AM
    Moderator
  • Thanks a lot Yan and Kivito! You gave me excellent guidance to finish this example.

    I'll do my best and I will post results here!

    (please give me some time, I am rather busy and don't do much Lightswitch sometimes)

    Friday, January 27, 2012 8:26 AM
  • No problem, you're welcome.

    I hope you find that missing "n" too, lol. (Yan --> Yann)


    Yann - LightSwitch Central - Click here for FREE Themes, Controls, Types and Commands
     
    If you find a reply helpful, please click "Vote as Helpful", if a reply answers your question, please click "Mark as Answer"
     
    By doing this you'll help people find answers faster.
    Friday, January 27, 2012 8:59 AM
    Moderator
  • My example done by checkboxes looks like this

    It is a nice solution! No need for advanced scenario here :)

    For limited nr. of employees this is great, but for bigger numbers it would be nice to make an autocomplete combo box do the job.

    Still trying, but no success. Fighting with querys and parameters. :P

    I will ask Yann for more help! :)

    Also, thanks for the "spasol.wordpress.com" - nice articles! Will come in handy when I try publishing.

    Friday, January 27, 2012 1:05 PM
  • Hello, Yann! And sorry about the "n"!!!

    What I managed to do so far is to make a query that would exclude some employes, but not in the correct manner :(

    I have a parameter "reserved" which is bound to EmployeesOnTasks.SelectedItem.Employee.Id

    Employees query then excludes "reserved" employees (the column in the picture on right side).

    It only throws out employees that are currently in focus (selected on "employees on tasks")

    That leaves me with 2 questions:

    1. How to get it to expell all reserved employees?

    2. How to make use of such query to become combobox for selecting employees on tasks? (when I try drag'n'drop, I never get combobox offered, but just datagrid or list)

    If this is a really simple matter, solution should not be so complicated :(

    This is what I have so far:

     

    Friday, January 27, 2012 1:21 PM
  • DomogojBulat,

    Great question... I am actually having the same problem and have been searching for a solution for a couple of days. Have you figured out how to do this yet?

    Tuesday, March 06, 2012 2:46 PM
  • No, I think the trouble is because many-to-many relation is currently supported only with checkboxes control.

    Thanks to Kivito's suggestion I used that solution and that is OK for me.

    I hope they are working on the new control with combo box. Looking forward to new updates on LightSwitch!

    Sunday, March 11, 2012 9:34 AM
  • This is not an issue. Selecting the AutoCompleteBox of the employee in the properties on the right you can select this query as source. Select this QryEmployees instead of Auto.

    The problem is that this query will be up to date only after every refresh. I mean in the example presented adding Marko to the task will not (and there is no way to do this with standard LS methods) be removed from the list of available employees. Only, after saving and refreshing you will have coherent interface again.

    About your query:

    Create a query on Employees (e.g. QryEmployees).

    Add a parameter int taskId required and then write 

    partial void QryEmployees_PreProcessQuery(int taskId){

      query = query.Where(e=>!e.Reserved && e.EmployeesOnTasks.FirstOrDefault(et=>et.Task.Id.Equals(taskId)) == null);

    }

    When you add this query to your screen, on the left select taskId parameter of qryEmployees and on the right in properties bind this parameter to Tasks.SelectetItem.Id.

    That's it.


    1+1 = 3 for large values of 1




    Sunday, March 11, 2012 10:00 AM