Solved

Datagridview ComboboxColumn value

Posted on 2010-11-12
3
447 Views
Last Modified: 2012-08-13
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.ToString) --> This gets me the valuemember.  What can I do to get the Displaymember and assign its value to a variable?
0
Comment
Question by:oak29
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 7

Expert Comment

by:50cal
ID: 34124361
0
 
LVL 17

Accepted Solution

by:
Zhaolai earned 500 total points
ID: 34125131
Try this:
Dim oCell As DataGridViewComboBoxCell = CType(.Cells("column_name", DataGridViewComboBoxCell)
if oCell IsNot Nothing Then
    Somevariable = oCell.DisplayMember
End If

Open in new window

0
 
LVL 32

Expert Comment

by:Erick37
ID: 34125401
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.ToString)
''lookup the Display value in the datasource using the Value
Dim dr As DataRow = ds.Tables.Item(0).Rows.Find(Somevariable)
Dim DisplayValue As String = dr.Item("SomeColumn")
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question