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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Kirtan PatelRank #292 · 8.6K reputationPosted Oct 21, 2009, 3:10 AM EDT
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 paxRank #2,843 · 502 reputationPosted Oct 21, 2009, 2:20 AM EDT
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]