开发者

How to make ComboBox column in DataGridView?

开发者 https://www.devze.com 2023-03-16 00:56 出处:网络
I have DataGridView with 2 columns: Fname | Age I need to show Age in ComboBox (that i can pick the age b开发者_JS百科etween 1 to 100).

I have DataGridView with 2 columns:

Fname | Age

I need to show Age in ComboBox (that i can pick the age b开发者_JS百科etween 1 to 100).

When I press the button (save button for example) the Age value will be saved to the database. (I work with access)

Can i get any sample in C# for this?


Did you check MSDN? It has a good example at DataGridViewComboBoxColumn Class.


Have you tried using a DataGridViewComboBoxColumn?

This "represents a column of DataGridViewComboBoxCell objects", each of which display a ComboBox control in the DataGridView.

The above-linked MSDN documentation also has an example of how you might implement this. But it's even easier to do from the Visual Studio designer; you don't even have to write a single line of code.


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];
0

精彩评论

暂无评论...
验证码 换一张
取 消