How to make ComboBox column in DataGridView?
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).
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];
精彩评论