Home Forums WinForms controls Other WinForms controls Set Wincombobox selection in code

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #18381 |

    Can someone please point me in the direction of how to set a wincombobox to a particular item in code. I have a an unbound form with wincombobox controls and I need to set them to a default selection based on values in textboxes on the form.

    Imported from legacy forums. Posted by Phil (had 2589 views)

    User (Old forums)
    Member
    Post count: 23064

    You can use one of the 3 methods below :

    1)
    winComboBox1.SelectedIndex = 2;

    2)
    object[] obj = new object[ 1 ];
    obj[ 0 ] = “select4”;
    ComboBoxItem item = new ComboBoxItem( obj );
    winComboBox1.Items.Add( obj );
    winComboBox1.SelectedItem = item;

    3)
    //requires the ValueMember to be set to work, thus works only in a bound context
    winComboBox1.SelectedValue = “select1”;

    Imported from legacy forums. Posted by André (had 3650 views)

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.