c# 如何在datagridview中实现下拉列表可变的联动combobox
展开全部
private void datagridView_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
DataGridView dataGridView = (DataGridView)sender;
if(dataGridView.CurrentCell.OwningColumn.Name == "yourCombobox")
{
ComboBox comboBox = (ComboBox)e.Control;
comboBox.SelectedIndexChanged += new EventHandler(comboBox_SelectedIndexChanged);
}
}
void comboBox_SelectedIndexChanged(object sender, EventArgs e)
{
银芹 ComboBox comboBox = (ComboBox)sender;
if (dataGridView.CurrentCell.OwningColumn.Name == "yourCombobox")
{
if (comboBox.Text != "")
{
this.SendComboBoxDataSource.DataSource = query(comboBox.Text);
}
}
}
首先通过这个埋正EditingControlShowing事件响应,为第一弯搏悔个ComboBox添加一个SelectedIndexChanged的事件,在SelectedIndexChanged事件中,绑定第二个ComboBox的数据源。大致思路是这样,仅供参考。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询