hI,
In my previouse post i have added ahow to add combo boxes to the DataGridView control. Now i need to set first item in the combox as the defualt selected value?
Unlike other combo boxes it doesnt have the selectedIndex....
TY
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Kirtan PatelPosted Oct 21, 2009, 7:10 AM
please check "Do you like this answer" :)
private void button1_Click(object sender, EventArgs e)
{
DataGridViewComboBoxCell cell = new DataGridViewComboBoxCell();
cell.Items.Add("Test");
cell.Items.Add("Test2");
DataGridViewColumn clm = new DataGridViewColumn(cell);
dataGridView1.Columns.Add(clm);
//Add Sample Rows in DataGridView
for (int i = 0; i <= 9; i++)
{
dataGridView1.Rows.Add();
}
//Set Default Values in Combobox Column Here Column Index is 0
foreach (DataGridViewRow r in dataGridView1.Rows)
{
dataGridView1.Rows[r.Index].Cells[0].Value = cell.Items[1].ToString();
dataGridView1.UpdateCellValue(0, r.Index);
}
}
naura paxPosted Oct 21, 2009, 6:20 AM
in the RowAdded event of datagridview
you can set cell value with
grd.Rows[e.RowIndex].Cells["cmbLedger"].Value=((DataGridViewComboBoxColumn)grd.Columns["cmbLedger"]).Items[0]