Set SelectedIndex for DataGridViewComboBoxCell

Đoạn code sau hướng dẫn cách thiết lập DataGridViewComboBox Column trong windows Forms

DataTable dt = null;
private void Form1_Load(object sender, EventArgs e)
dt = new DataTable();
DataRow dr = dt.NewRow();
dr[“Category”] = “Select All”;
DataRow row = dt.NewRow();
row[0] = “Cat 1”;
DataRow row2 = dt.NewRow();
row2[0] = “Cat 2”;
DataGridViewComboBoxColumn newColumn = new DataGridViewComboBoxColumn();
newColumn.Name = “Category”;
newColumn.DataSource = dt;
newColumn.DisplayMember = “Category”;
newColumn.ValueMember = “Category”;

private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
this.dataGridView1.Rows[e.RowIndex].Cells[0].Value = dt.Rows[0][0].ToString();


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s