Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Datagridview ComboboxColumn value

Posted on 2010-11-12
3
Medium Priority
?
455 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 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Integration Management Part 2
Suggested Courses

963 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