Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.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
将DataGridViewComboxCell添加到GridView c#_C#_Gridview_Combobox - Fatal编程技术网

将DataGridViewComboxCell添加到GridView c#

将DataGridViewComboxCell添加到GridView c#,c#,gridview,combobox,C#,Gridview,Combobox,看起来很简单,但由于某些原因,在这上面工作了4个小时却没有结果。 我有一个简单的Gridview,其中有两列和几行已经填充,现在我想将ComboBoxCell添加到下一行 我会展示我的逻辑,也许你会展示我的错误: SampleGridView.Rows.Add("test1", "test1"); SampleGridView.Rows.Add("test2", "test2"); SampleGridView.Rows.Add("test3", "test3"); 适用于三行,现在插入组合框

看起来很简单,但由于某些原因,在这上面工作了4个小时却没有结果。 我有一个简单的Gridview,其中有两列和几行已经填充,现在我想将ComboBoxCell添加到下一行

我会展示我的逻辑,也许你会展示我的错误:

SampleGridView.Rows.Add("test1", "test1");
SampleGridView.Rows.Add("test2", "test2");
SampleGridView.Rows.Add("test3", "test3");
适用于三行,现在插入组合框:

DataGridViewRow RowSample = new DataGridViewRow();
DataGridViewComboBoxCell  CellSample = new DataGridViewComboBoxCell();
CellSample.DataSource = StringList; // list of the items that I want to insert in ComboBox
RowSample.Cells.Add(CellSample);
SampleGridView.Rows.Add(RowSample);
有什么想法吗?多谢各位

DataGridViewComboBoxColumn combo = new DataGridViewComboBoxColumn();
combo.datasource = stringlist;

SampleGridView.Columns.Add(combo);
这是我脑子里想不出来的,但应该能用。

想出来:)我试图将ComboBox插入行的第二个单元格,但没有用。我试着这样做:

SampleGridView.Rows.Add("CellText", RowSample);
但实际上必须是这样

DataGridViewRow RowSample = new DataGridViewRow();
DataGridViewComboBoxCell  CellSample = new DataGridViewComboBoxCell();
CellSample.DataSource = StringList; // list of the string items that I want to insert in ComboBox
CellSample.Value = StringList[0]; // default value for the ComboBox
DataGridViewCell cell = new DataGridViewTextBoxCell();
cell.Value = "CellText"; // creating the text cell
RowSample.Cells.Add(cell);
RowSample.Cells.Add(CellSample);
SampleGridView.Rows.Add(RowSample);

对不起,伙计,我想是在ASP.NET中。这是WinForms,对吗?这会在列中添加组合框,但不会在特定行中添加组合框。是否希望每行有不同的数据源?基本上只有一行必须是组合框,所有其他行都必须是文本行。这就是我讨厌Microsoft的原因。