Click here to Skip to main content
15,880,469 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

I have an gridview with text box and combobox.
I have binded the combo box values from dataset but i can see value member in grid ,when i select the combo box in the list i can see display member.
How can i make display member to see.
Here is the sample code
C#
ds.Tables["GGPI"].Columns.Add("doseqty");
           ds.Tables["GGPI"].Columns.Add("doseid");
           ds.Tables["GGPI"].Columns.Add("timesqty");
           ds.Tables["GGPI"].Columns.Add("timesid");

C#
doseid.DataSource = Stock.GetDoseList();
           doseid.DataPropertyName = "Doseid";
           doseid.DisplayMember = "DoseDesc";
           doseid.ValueMember = "DoseId";
Posted
Comments
Mayur Panchal 17-May-13 6:15am    
I have tested what u want to do with some sample data :

dtCombo.Columns.Add("DoseDesc");
dtCombo.Columns.Add("DoseId");
dtCombo.Rows.Add(new object[] { "Dose1", 1 });
dtCombo.Rows.Add(new object[] { "Dose2", 2 });
dtCombo.Rows.Add(new object[] { "Dose3", 3 });
dtCombo.Rows.Add(new object[] { "Dose4", 4 });

doseid.DataSource = dtCombo;
doseid.DataPropertyName = "Doseid";
doseid.DisplayMember = "DoseDesc";
doseid.ValueMember = "DoseId";


dt.Columns.Add("doseqty");
dt.Columns.Add("doseid");
dt.Columns.Add("timesqty");
dt.Columns.Add("timesid");

dt.Rows.Add(new object[] { 500, 1, 3, 1 });
dt.Rows.Add(new object[] { 100, 2, 3, 1 });
dt.Rows.Add(new object[] { 500, 3, 3, 1 });
dt.Rows.Add(new object[] { 300, 4, 3, 1 });

dataGridView1.DataSource = dt;

and its working nice..I can see display member (Dose1 ,Dose2...)
Is anuthing different than let me know..

1 solution

Hello,
Try this out sample code


DataTable dt = new DataTable();

dt.Columns.Add("doseDesc");
dt.Columns.Add("doseid");
dt.Columns.Add("timesqty");
dt.Columns.Add("timesid");

dt.Rows.Add(new object[]{"aaa","id1","q1",4});
dt.Rows.Add(new object[] {"bbb", "id2", "q2", 44 });


DataGridViewTextBoxColumn txtCol = new DataGridViewTextBoxColumn();
DataGridViewComboBoxColumn comboCol = new DataGridViewComboBoxColumn();
comboCol.DataSource = dt;
comboCol.DisplayMember = "doseDesc";
comboCol.ValueMember = "doseid";

dataGridView1.Columns.Add(txtCol);
dataGridView1.Columns.Add(comboCol);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900