添加DataGridViewComboBoxCell到GridView c# [英] Add DataGridViewComboBoxCell to GridView c#
本文介绍了添加DataGridViewComboBoxCell到GridView c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
似乎这么简单,但由于某种原因工作在它最后4小时没有结果。
我有简单的Gridview与两列和几行已经填充,现在我想添加ComboBoxCell到下一行。
Seems like it's so simple but for some reason working on it last 4 hours with no result. I have simple Gridview with two columns and few rows already filled, now I want to add ComboBoxCell to the next row.
我会显示我的逻辑和也许你会告诉我我的错误:
I'll show my logic and maybe you'll show me my error:
SampleGridView.Rows.Add("test1", "test1");
SampleGridView.Rows.Add("test2", "test2");
SampleGridView.Rows.Add("test3", "test3");
现在可以插入我的ComboBox了:
works fine for three rows now I am inserting my ComboBox:
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);
任何想法?谢谢
推荐答案
想办法:)我试图插入ComboBox到行的第二个单元格, t工作。我试图这样做:
figured it out :) I was trying to insert ComboBox to the second cell of the row, and it didn't work. I was trying to do it like this:
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);
这篇关于添加DataGridViewComboBoxCell到GridView c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文