Solved

Datagridview ComboboxColumn value

Posted on 2010-11-12
3
445 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
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

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 …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

816 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

11 Experts available now in Live!

Get 1:1 Help Now