2011-06-27 51 views
3

我有DataGridView 2列:如何在DataGridView中创建ComboBox列?

Fname | Age 

我需要显示在ComboBoxAge(我可以挑1之间的年龄到100)。
当我按下按钮(例如保存按钮)时,Age值将被保存到数据库中。 (我与访问工作)

我可以在C#中获得任何示例为此?

回答

1

您是否尝试过使用DataGridViewComboBoxColumn

此“表示一列DataGridViewComboBoxCell对象”,其中每个对象都在DataGridView中显示一个ComboBox控件。

上述链接的MSDN文档还提供了一个示例,说明如何实现此目的。但从Visual Studio设计人员做起更容易;你甚至不必编写一行代码。

+0

你能帮我设计和填充datagridview(winforms)中的列(索引1)是一个comboboxcolumn吗? – Sukanya

-2
string value = combodisease.SelectedItem.ToString(); 
string str = "select test, normal, high, cost from testname join testcost on testcost.testid=testname.testid where test='"+value+"'"; 
SqlDataAdapter da = new SqlDataAdapter(str, cn); 
DataSet ds = new DataSet(); 
da.Fill(ds); 
dataGridView1.DataSource = ds.Tables[0];