想实现下拉菜单的关联,比如选择第一列工序,第二列便只出现与它有关的内容,但在选择第二列时,不知为何总是报错,相关的代码与截图如下,请指点一下,是哪里的问题;
private void ComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
DataGridViewComboBoxEditingControl processcolumn = sender as DataGridViewComboBoxEditingControl;
string selectedprocess = processcolumn.SelectedValue.ToString();
int currentColumnIndex = dataGridView1.CurrentCell.ColumnIndex;
int nextColumnIndex = currentColumnIndex + 1;
// 根据当前列的索引来判断下一列是否存在
if (nextColumnIndex < dataGridView1.Columns.Count)
{
DataGridViewComboBoxColumn nextColumn = dataGridView1.Columns[nextColumnIndex] as DataGridViewComboBoxColumn;
// 根据选中的产品,筛选出对应的规格信息
List<string> filteredprocessList = GetFilteredprocessList(selectedProcess);
nextColumn.DataSource = filteredprocessList;
}
}
private List<string> GetFilteredprocessList(string product)
{
// 根据选中的产品,返回对应的规格列表
// 这里假设你有一个方法可以根据产品获取对应的规格信息
List<string> process = new List<string>();
switch (product)
{
case "制粒":
process = new List<string> { "产品1" };
break;
case "提取":
process = new List<string> { "产品2" };
break;
}
return process;
}
根据提供的参考资料,问题是关于下拉列表之间的关联问题。然而,参考资料中的代码与问题描述的代码不一致,无法准确判断问题的原因是什么。请提供更具体的代码和截图,以便更好地指导解决问题。