I am new to windows forms application development.
I am using an editable grid view for data entry.
One of the fields in the grid view is of type ComboBoxColumn. I am filling the data in code.
My problem is if data item count is greater than 0 then first item should be selected automatically.
My code from Page_Load()
is:
private void Form1_Load(object sender, EventArgs e)
{
cn = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\Study\sem 6\Practice\WindowsFormsApplication1\Practice.accdb");
cn.Open();
cmd = new OleDbCommand("Select * from Grade", cn);
da = new OleDbDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds);
cn.Close();
}
private void dataGridView1_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
{
DataGridViewComboBoxCell cmb = (DataGridViewComboBoxCell)(dataGridView1.Rows[e.RowIndex].Cells[1]);
cmb.DataSource = ds.Tables[0];
cmb.DisplayMember = "Grd";
cmb.ValueMember = "ID";
if(cmb.Items.Count > 0)
// Here I am not finding the the combo box's SelectedIndex Property.
}
Please help to solve this problem.
Thanks in advance.