0

In a Windows Application I have a Combobox in a DataGridView.

My question is:
How do I get the value at the first index as default?

For example, if the ComboBox Status has three values

  • unknown (1)
  • accepted (2)
  • rejected (3)

the value unknown is at the first index and should be selected as default in the DataGridView cell. The ComboBox's text should be set programmatically by index, e.g. by cbbox.selectindex = 1;

enter image description here

How can the first index's text be displayed by default in the DataGridView?

zx485
  • 28,498
  • 28
  • 50
  • 59
Awais Jan
  • 7
  • 6

2 Answers2

0

Are you using WPF or WinForms?

If you're using WPF, try this:

DataRowView dr = (DataRowView) YourDataGrid.SelectedItem;
YourComboBox.Text = dr.Row[0].ToString();

Are you asking on how to get the first index value of your datagrid?

zekromWex
  • 280
  • 1
  • 4
  • 17
0

In the Designer, you can set the column's DefaultCellStyle NullValue.

dataGridView1.Columns[3].DefaultCellStyle.NullValue = "unknown";
Slai
  • 22,144
  • 5
  • 45
  • 53