Click here to Skip to main content
13,895,532 members
Rate this:
 
Please Sign up or sign in to vote.
See more:
Hi All,

i have a problem SETTING the DatagridviewComboBoxColumn selectedValue.

I have a grid that has 2 DatagridviewComboBoxColum.

please see the code below.
DataTable datatable = new DataTable(DataSourceTable);
                     datatable = oDbConnection.MYSQLExecuteNonQuery("SELECT  * FROM "+ DataSourceTable , datatable);
                     DataGridViewComboBoxColumn oCol = new DataGridViewComboBoxColumn();

                     oCol.Name = ColumnName;
                     oCol.HeaderText = HeaderText;
                     oCol.DisplayMember = DisplayMember;
                     oCol.ValueMember = ValueMember;
                     oCol.DataPropertyName = ValueMember;
                     oCol.DataSource = datatable;
                     DgView.Columns.Add(oCol);



where ValueMember = "ProjectID"
and DisplayMember = "ProjectDescrption"

i dont have probelem GETing the value of the DatagridviewComboBoxColum

the problem is when i set the DatagridviewComboBoxColum value when i load the data in the datagridview which has ComboBox from the database.

instead displaying of DISPLAYMEMBER data, the comboBox Displying VALUEMEMBER.

thanks.
Posted
Updated 11-Jan-19 19:24pm
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

If you mean the the combobox is showing the value member data (data from Id column) instead of data from ProjectDescription column, then use the debugger to check that your variables (DisplayMember and ValueMember) contain correct column names.

If you mean that the display member data isn't showing the data at all, check that the column name is spelled correctly. Should the
DisplayMember = "ProjectDescrption"

be
DisplayMember = "ProjectDescription"
   
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Hi,

The spelling is correct. what i'm trying to figure is how to SET the SELECTEDVALUE of the DatagridViewComboBoxColumn.


as per MSDN, the DatagridViewComboBoxColumn has no property of SELECTEDVALUE but VALUE.
   
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

in grid view combobox cell property value act as both selected value and selected text.
if you want to set grid combo selected value it only accepts integer type. if assigned value is string it automatically sets selected text of the grid combo.

eg:

dgv_Sales.Rows[i].Cells["grid_cmbUnit"].Value = 1 // this line of code sets selectedvalue


dgv_Sales.Rows[i].Cells["grid_cmbUnit"].Value = "KG" //this line of code sets selectedtext
   

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Cookies | Terms of Service
Web02 | 2.8.190306.1 | Last Updated 12 Jan 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100