Solved

Datagridview ComboboxColumn value

Posted on 2010-11-12
3
443 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
3 Comments
 
LVL 7

Expert Comment

by:50cal
Comment Utility
0
 
LVL 17

Accepted Solution

by:
Zhaolai earned 500 total points
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now