10
Answers

datagridviewcomboboxcolumn select the first item

abid zaid

abid zaid

17y
26.2k
1

Hi all,
I'm using a Datagridviewcomboboxcolumn in to dsiplay some data in my datagridview. After binding the data to the datagridviewcombobox how can i make it display the first item in the box by default?
My code is as follow
DataGridViewComboBoxColumn col = new DataGridViewComboBoxColumn();
            DataTable dt = getData();//get data from database
            col.DataSource = dt;
            col.DisplayMember = "LastName";
            if (col.Items.Count > 0)//There is at least one item in the Combobox
            {
                //Select the first item
            }
            dataGridView1.Columns.Add(col);
Answers (10)