Link to home
Start Free TrialLog in
Avatar of si2030
si2030

asked on

returning the valuemember of a datagridviewcombobox.

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

Simon
'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.
            .Columns.Add(accountComboBox)
 
        End With

Open in new window

Avatar of Jeff Certain
Jeff Certain
Flag of United States of America image

I'm not entirely sure what you're asking here. I would think that accountComboBox.SelectedValue would give you what you're after.
Avatar of si2030
si2030

ASKER

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"?

Simon
Avatar of si2030

ASKER

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...
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?
ASKER CERTIFIED SOLUTION
Avatar of si2030
si2030

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.