如何在DataGridView中实现下拉列表可变的联动ComboBox
1个回答
推荐于2016-02-23
展开全部
首先通EditingControlShowing事件响应第ComboBox添加SelectedIndexChanged事件SelectedIndexChanged事件绑定第二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);
}
}
}
{
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);
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询