[Webinar] Learn how to a build a cloud-first strategyRegister Now


returning the valuemember of a datagridviewcombobox.

Posted on 2009-02-18
Medium Priority
Last Modified: 2012-05-06
Hi Experts,

I have a datgridviewcombobox column with a display member and value member. I want to retrieve the valuemember so I can apply the data to file.

I am unsure if I have:

1:applied the valuemember/display member correctly.

The binding source is a LINQ result set with two members:
acc_id and accList.

2: How do I retrieve the valuemember from the selected value in the datagridviewcombobox cell.

What code would I write to retireve this value member?

Kind Regards

'Create the binding sources.
        Dim BSAccountComboBox As New BindingSource
        'Apply the binding sources.
        BSAccountComboBox.DataSource = accountList
        With accountComboBox
            .Name = "account"
            .DataSource = BSAccountComboBox
            .HeaderText = "Account"
            .DisplayMember = "accList"
            .ValueMember = "acc_id"
            .DropDownWidth = accComboBoxDropDwnWidth
            .DefaultCellStyle.BackColor = Color.WhiteSmoke
            .Width = 220
            .FlatStyle = FlatStyle.Flat
            .MaxDropDownItems = 10
  With dgvCreditorInvoiceDetail
            'Add the accountComboBox column to the DataGridView control.
        End With

Open in new window

Question by:si2030
  • 3
  • 3
LVL 24

Expert Comment

by:Jeff Certain
ID: 23677215
I'm not entirely sure what you're asking here. I would think that accountComboBox.SelectedValue would give you what you're after.

Author Comment

ID: 23678262
Hi Chaosian,

How would you use accountComboBox.SelectedValue for a specific row... say I have three rows each with a differernt selected value whats the line for "accountComboBox.SelectedValue"?


Author Comment

ID: 23678293
Say the drop down value or DisplayMember is "10000 Debtors" then the valuemember is "123". I want to obtain the value member - 123 - when this option is selected in the datagridviewcombobox. It may be that there are two or more rows filled in the datagridview then for each cell in the datagiridview in the datagridviewcombobox column I want to get the valuemember not the displaymember...

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

LVL 24

Expert Comment

by:Jeff Certain
ID: 23680889
Just to make sure I understand what you're after, it sounds like there are two issues at hand.
1. How do you get the value for the combo box in a specific row of the grid?
2. How do you get the value rather than the text?

Accepted Solution

si2030 earned 0 total points
ID: 23681226
Hi Chaosian

I think I have worked out how to obtain these now...

 Dim test = dgvCreditorInvoiceDetail.CurrentCell.Value
        Dim test4 = dgvCreditorInvoiceDetail.Item(0, 0).Value
        Dim test1 = dgvCreditorInvoiceDetail.Rows(0).Cells(0).Value

These all work for the value.

The thing is, you cant obtain it in a cell validating event... it equals zero.

you can however use:
Dim comboBoxColumn As DataGridViewComboBoxColumn = dgvCreditorInvoiceDetail.Columns("account")


LVL 24

Expert Comment

by:Jeff Certain
ID: 23681469
The validating event issue makes sense -- the selected item likely hasn't been changed yet. Validation would occur first. I would, however, expect to have the correct value in a CellChange event.

Sounds like you've got this well in hand.

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
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 …
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month20 days, 12 hours left to enroll

865 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