oak29
asked on
Datagridview ComboboxColumn value
I have a datagridview comboboxcolumn that has a valuemember and a displaymember. The valuemember is saved in the database and I need to use displaymember for a calculation. All I can seem to get is the valuemember for the database.
Somevariable = CDbl(.Cells("column_name") .Value.ToS tring) --> This gets me the valuemember. What can I do to get the Displaymember and assign its value to a variable?
Somevariable = CDbl(.Cells("column_name")
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
DisplayMember will give you the name of the property (or column) in the datasource that the control is bound to.
To get the Text that is displayed in the cell, you could use the Value property and do a lookup for the corresponding Display Value in the datasource.
e.g.
Somevariable = CDbl(.Cells("column_name") .Value.ToS tring)
''lookup the Display value in the datasource using the Value
Dim dr As DataRow = ds.Tables.Item(0).Rows.Fin d(Somevari able)
Dim DisplayValue As String = dr.Item("SomeColumn")
To get the Text that is displayed in the cell, you could use the Value property and do a lookup for the corresponding Display Value in the datasource.
e.g.
Somevariable = CDbl(.Cells("column_name")
''lookup the Display value in the datasource using the Value
Dim dr As DataRow = ds.Tables.Item(0).Rows.Fin
Dim DisplayValue As String = dr.Item("SomeColumn")
http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewcomboboxcolumn.valuemember.aspx
50cal.