locked
Populate listbox with multiple selected values RRS feed

  • Question

  • Hi,  maybe this is a really simple question, but I've been struggling.

    I have a multisimple listbox.  I'm trying to populate it from the SQL database. For example, one column in the database contains multiple languages. In the listbox, I have 196 languages which is populate it form different table. What I want to do is when the person is selected, I show in the listbox the languages that he speaks to be highlighted and show on the top of the list....

    For example:

    Column in database:

    UserA ::    Languages

    User::       English, Spanish, French

    Listbox already contains 196 languages. For the selected person, I want the listbox to highlighted those three languages and show it on the top of the listbox.

    Any help?

    Monday, January 28, 2013 2:55 AM

Answers

  • if (this.lbDivisionCode.SelectedIndices.Count != 0)
                        {
                            for (int i = 0; i < this.lbDivisionCode.Items.Count; i++)
                            {
                                if (this.lbDivisionCode.GetSelected(i) == true)
                                {
                                    this.lbDivisionID.SetSelected(i, true);
                                }
                                else
                                {
                                    this.lbDivisionID.SetSelected(i, false);
                                }
                            }


    Mark Answered, if it solves your question and Vote if you found it helpful.
    Rohit Arora

    • Proposed as answer by Jason Dot Wang Tuesday, January 29, 2013 6:14 AM
    • Marked as answer by Jason Dot Wang Monday, February 4, 2013 6:39 AM
    Monday, January 28, 2013 6:15 AM

All replies

  • You might want to consider moving this question to

    Windows Forms: http://social.msdn.microsoft.com/Forums/en-US/winforms/threads

    or

    Windows Presentation Foundation: http://social.msdn.microsoft.com/Forums/en-US/wpf/threads

    Depending upon which technology you are using, because the answer will likely be somewhat different depending upon your base.

    Floating the languages to the to is a sorting issue and will likely depend upon the relationships in your queries.

    Selection will probably involve setting isSelected or Selected properties for the items.


    It would be greatly appreciated if you would mark any helpful entries as helpful and if the entry answers your question, please mark it with the Answer link.

    • Proposed as answer by Jason Dot Wang Tuesday, January 29, 2013 6:14 AM
    • Unproposed as answer by Jason Dot Wang Tuesday, January 29, 2013 6:19 AM
    Monday, January 28, 2013 3:46 AM
  • if (this.lbDivisionCode.SelectedIndices.Count != 0)
                        {
                            for (int i = 0; i < this.lbDivisionCode.Items.Count; i++)
                            {
                                if (this.lbDivisionCode.GetSelected(i) == true)
                                {
                                    this.lbDivisionID.SetSelected(i, true);
                                }
                                else
                                {
                                    this.lbDivisionID.SetSelected(i, false);
                                }
                            }


    Mark Answered, if it solves your question and Vote if you found it helpful.
    Rohit Arora

    • Proposed as answer by Jason Dot Wang Tuesday, January 29, 2013 6:14 AM
    • Marked as answer by Jason Dot Wang Monday, February 4, 2013 6:39 AM
    Monday, January 28, 2013 6:15 AM