Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何以编程方式更改datagridview中的combobox选定项?_C#_.net_Datagridview_Combobox - Fatal编程技术网

C# 如何以编程方式更改datagridview中的combobox选定项?

C# 如何以编程方式更改datagridview中的combobox选定项?,c#,.net,datagridview,combobox,C#,.net,Datagridview,Combobox,如何以编程方式更改datagridview中的combobox选定项?在datagridview CellClick事件中: private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { string item = dataGridView1.SelectedCells[0].Value.ToString(); comboBox1.SelectedItem = item;

如何以编程方式更改datagridview中的combobox选定项?

在datagridview CellClick事件中:

private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
     string item = dataGridView1.SelectedCells[0].Value.ToString();
     comboBox1.SelectedItem = item;
}

使用暴力。假设要更改列colIndex和行rowIndex中DataGridViewComboxCell的值,并且combobox的值索引位于0位置:

For jj = 0 To CType(myDatagrid.Rows(rowIndex).Cells(colIndex), DataGridViewComboBoxCell).Items.Count - 1
    If CInt(CType(myDatagrid.Rows(colIndex).Cells(rowIndex), DataGridViewComboBoxCell).Items(jj).row(0)) = myValue Then
        myDatagrid.Rows(rowIndex).Cells(colIndex).Value = CType(myDatagrid.Rows(rowIndex).Cells(colIndex), DataGridViewComboBoxCell).Items(jj).row(0)
    End If
Next
是的,我知道这个问题是6年前提出的,但我在任何地方都没有找到答案,我是自己找到的。希望它对某人有用


DataGridViewComboxCell没有选择Index或selectedValue属性的原因我无法理解。

只要将单元格值更改为ComboxColumn中的一项,它就会自动为您选择。因此,请在回答中给我一个代码示例:我们都知道理论部分:要么写答案,要么什么都不写。0逻辑在这里编写代码。