Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > DataGridViewComboBoxColumn Problem - Showing Value Member instead of Display Member
 

DataGridViewComboBoxColumn Problem - Showing Value Member instead of Display Member

Hello,

I'm trying to have a combobox column in my datagrid that contains file types records from a datatable (dtFileTypes).

I've provided the column with the DataPropertyName, DataSource, DisplayMember and Value Member information, and still the datagrid shows the value member inside the combobox.

On form load:

gcBatchFileType.DataPropertyName = "Type"

gcBatchFileType.DataSource = dtFileTypes

gcBatchFileType.DisplayMember = "Text"

gcBatchFileType.ValueMember = "ID"

Please Help...

tzahgr  Wednesday, October 22, 2008 4:55 PM

Hi tzahgr,

Didn’t the comboBox column display Text field? Actually, I found no problem with your code, and it should be OK. Please try the following code which I programmatically build a datatable and bind it to the DataGridViewComboBox Column.

Code Snippet

DataTable dt = new DataTable();

dt.Columns.Add("ID", typeof(int));

dt.Columns.Add("Text", typeof(string));

dt.Columns.Add("Type", typeof(string));

DataRow dr = dt.NewRow();

dr["ID"] = 1;

dr["Text"] = "xmsd";

dr["Type"] = "video";

DataRow dr1 = dt.NewRow();

dr1["ID"] = 2;

dr1["Text"] = "ddf";

dr1["Type"] = "xml";

dt.Rows.Add(dr);

dt.Rows.Add(dr1);

this.Column1.DataPropertyName = "Type";

this.Column1.DataSource = dt;

this.Column1.DisplayMember = "Text";

this.Column1.ValueMember = "ID";

Column1 is DataGridViewComboBoxColumn.

Best Regards,

Bruce Zhou

Bruce.Zhou  Monday, October 27, 2008 8:15 AM

Hi tzahgr,

Didn’t the comboBox column display Text field? Actually, I found no problem with your code, and it should be OK. Please try the following code which I programmatically build a datatable and bind it to the DataGridViewComboBox Column.

Code Snippet

DataTable dt = new DataTable();

dt.Columns.Add("ID", typeof(int));

dt.Columns.Add("Text", typeof(string));

dt.Columns.Add("Type", typeof(string));

DataRow dr = dt.NewRow();

dr["ID"] = 1;

dr["Text"] = "xmsd";

dr["Type"] = "video";

DataRow dr1 = dt.NewRow();

dr1["ID"] = 2;

dr1["Text"] = "ddf";

dr1["Type"] = "xml";

dt.Rows.Add(dr);

dt.Rows.Add(dr1);

this.Column1.DataPropertyName = "Type";

this.Column1.DataSource = dt;

this.Column1.DisplayMember = "Text";

this.Column1.ValueMember = "ID";

Column1 is DataGridViewComboBoxColumn.

Best Regards,

Bruce Zhou

Bruce.Zhou  Monday, October 27, 2008 8:15 AM

I am experiencing the same problem as tzahgr. The databound combobox displays the proper text (DisplayMember) in the visual portion of the drop down but when you tab off the cell the combobox displays the ValueMember. (VS2008 - DataGridView - DataGridViewComboBoxCell)
mjhillman  Wednesday, November 05, 2008 7:33 PM
Hi,
I too have the same problem. Did u find the solution for:

"I am experiencing the same problem as tzahgr. The databound combobox displays the proper text (DisplayMember) in the visual portion of the drop down but when you tab off the cell the combobox displays the ValueMember. (VS2008 - DataGridView - DataGridViewComboBoxCell):"

Pls reply if u did with the solution.

Thanks,
Sumit
sumitshah4u  Tuesday, July 21, 2009 11:35 AM
i was having same problem too.it was happening because datasets are not updating themselves automatically from db(as normal)

I changed column data type from db(varchar to int).After that i see my datasets columntype didnt changed.It still shown as string.When i changed it to Integer the problem solved.

Sorry for bad english and hope this helps...
YeniÇeri  Tuesday, August 25, 2009 9:47 AM

You can use google to search for other answers

Custom Search

More Threads

• DBNull, defaultvaluesneeded ?????
• Help me in arabic in vb.net 2005
• Displaying Names rather than IDs in a ComboBox
• How Do I Update My BindingSource?
• Databind DataGridView HELP.....
• hide rows in datagridview
• datagrid against DataSource reflection of virtual properties
• DataGridTextBoxColumn Bug
• DataGridView KeyPress Event Not Working
• adding record to the binding source progammically...