locked
Multiselect view in the listbox RRS feed

  • Question

  • Hey all,
    I wanted some help..
    Scenario,
    i wanted to higlight multiple values in a listbox based on the database..

    say a student is allocated to different subjects..
    so i wanted to show when a particular student is selected, the subjects that he is allocated to shud get selected from the list of all the available subjects.

    I somehow cant able to do it one at a time cuz it gets overwritten and the last subject is only highlighted...

    heres the code..

     foreach (Student tmp in _CollectionStud ) //(collection stud is an arraylist)
                {
                    foreach (ListItem _Tmp in _ListSubjects.Items)
                    {
                        if (tmp.PK_STUD_ID.ToString().Equals(_Tmp.Value))
                        {
                            //TODO Write code to higlight the correct ones
                            ArrayList tmpp ;
                              tmpp.Add (_ListClientTypes.Items.FindByValue(_TmpClient2.Value ));

                            _ListSubjects.SelectedValue = tmp.Value;

                            break;   
                        }
                    }
                }
    (so wat is happening is everytim it gets in the inner foreach loop the older one is overwritten)

    please let me know if there are other design ideas...

    Friday, August 18, 2006 6:20 AM

Answers

  • Instead of using the SelectedValue property of the ListBox, you need to set the Selected property of each item. By way of analogy, the second method is like the user ctrl-clicking items one at a time to get several selected. The first method is comparable to the user clicking on a single item -- erasing other selections.

    In your code, replace

    _ListSubjects.SelectedValue = tmp.Value;

    with

    _Tmp.Selected = true;

    Friday, August 18, 2006 8:37 AM

All replies

  • Instead of using the SelectedValue property of the ListBox, you need to set the Selected property of each item. By way of analogy, the second method is like the user ctrl-clicking items one at a time to get several selected. The first method is comparable to the user clicking on a single item -- erasing other selections.

    In your code, replace

    _ListSubjects.SelectedValue = tmp.Value;

    with

    _Tmp.Selected = true;

    Friday, August 18, 2006 8:37 AM
  • works like a charm!
    thank you!

    Sunday, August 20, 2006 11:52 PM