c# 在DataGridView控件中动态添加DataGridViewComboBoxCell单元格控件问题
privatevoiddataGridView1_CellMouseClick(objectsender,DataGridViewCellMouseEventArgse)...
private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
DataGridViewComboBoxCell comcell = new DataGridViewComboBoxCell();
String s = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
comcell.Value = s;
string[] strValue = new string[] { "True", "False", "北京", "上海", "南京" };
comcell.Items.AddRange(strValue);
dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex] = comcell;
}
private void dataGridView1_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
{
DataGridViewTextBoxCell tbcell = new DataGridViewTextBoxCell();
string s = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
tbcell.Value = s;
dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex] = tbcell;
}
红圈位置组合框点开,又立即缩回,导致无法选择数据!纠结啊!
表格的数据源是DataSet,不绑定外部数据:
dataGridView1.DataSource = dataSet1.Tables[0]; 展开
{
DataGridViewComboBoxCell comcell = new DataGridViewComboBoxCell();
String s = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
comcell.Value = s;
string[] strValue = new string[] { "True", "False", "北京", "上海", "南京" };
comcell.Items.AddRange(strValue);
dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex] = comcell;
}
private void dataGridView1_CellMouseLeave(object sender, DataGridViewCellEventArgs e)
{
DataGridViewTextBoxCell tbcell = new DataGridViewTextBoxCell();
string s = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
tbcell.Value = s;
dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex] = tbcell;
}
红圈位置组合框点开,又立即缩回,导致无法选择数据!纠结啊!
表格的数据源是DataSet,不绑定外部数据:
dataGridView1.DataSource = dataSet1.Tables[0]; 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询