locked
SelectedItem in ComboBox RRS feed

  • Question

  • Hi all,

    I have a datagrid containing a DataGridViewComboboxColumn, the combobox contains four items, when the form is loaded i want just to set the selecteditem to first item.
    How can I do it?

    Thanks. 
    Monday, July 28, 2008 9:45 AM

Answers

  • When the form is loaded I guess the grid is empty right !?  When you add new rows to the grid then you will set the value for the ComboBox column. Or is it that you want to set the value by its index and not the textual value?
    Please provide some more info.

    /Calle
    • Marked as answer by jack 321 Friday, August 1, 2008 2:48 AM
    Tuesday, July 29, 2008 3:21 PM
  • hi...


    Try this ot 

    suppose if u add these items in combo box..

    comboBox1.Items.Add("Item1sdsd ");

    comboBox1.Items.Add("Item2 sdfsdfsd");

    comboBox1.Items.Add("Item3 sdfsdfsd");

    comboBox1_SelectedIndexChanged(sender, e);

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)

    {

    comboBox1.SelectedIndex=1;// THEN IT WILL select "item2 sdfsdfsd"..........

    }


    Hope it will solve ur prob...

    • Marked as answer by jack 321 Friday, August 1, 2008 2:48 AM
    Tuesday, July 29, 2008 4:27 PM

All replies

  • When the form is loaded I guess the grid is empty right !?  When you add new rows to the grid then you will set the value for the ComboBox column. Or is it that you want to set the value by its index and not the textual value?
    Please provide some more info.

    /Calle
    • Marked as answer by jack 321 Friday, August 1, 2008 2:48 AM
    Tuesday, July 29, 2008 3:21 PM
  • hi...


    Try this ot 

    suppose if u add these items in combo box..

    comboBox1.Items.Add("Item1sdsd ");

    comboBox1.Items.Add("Item2 sdfsdfsd");

    comboBox1.Items.Add("Item3 sdfsdfsd");

    comboBox1_SelectedIndexChanged(sender, e);

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)

    {

    comboBox1.SelectedIndex=1;// THEN IT WILL select "item2 sdfsdfsd"..........

    }


    Hope it will solve ur prob...

    • Marked as answer by jack 321 Friday, August 1, 2008 2:48 AM
    Tuesday, July 29, 2008 4:27 PM