private void cmbInNa_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
DataTable dt1 = pbl.getinnm(this.cmbInNa.Text.ToString());
if (dt1 != null) //&& dt.Rows.Count > 0)
{
dataGridView1.DataSource = dt1;
DataGridViewComboBoxColumn cmbkw = dataGridView1.Columns["cmbkw"] as DataGridViewComboBoxColumn;
cmbkw.DataSource = dt1;
cmbkw.DisplayMember = "KeyWord";
DataGridViewComboBoxColumn cmbRetu = dataGridView1.Columns["cmbRetu"] as DataGridViewComboBoxColumn;
cmbRetu.DataSource = dt1;
cmbRetu.DisplayMember = "col_Return";
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
当我单击gridview
时,如何在combobox
中插入值,现在我可以使用上面的代码从数据库中检索数据,就像我想要插入的那样,当用户选择{时更新值{1}}。
答案 0 :(得分:0)
像这样添加行
DataGridView dg = new DataGridView();
//dg is your Datagridview
DataGridViewRow dgr = new DataGridViewRow();
dg.Rows.Add(dgr);
答案 1 :(得分:0)
这样做:
(dataGridView1.DataSource as DataTable).Rows.Add((dataGridView1.DataSource as DataTable).NewRow());