Link to home
Start Free TrialLog in
Avatar of BlakeMcKenna
BlakeMcKennaFlag for United States of America

asked on

Bound DataGridViewComboBoxCell returning the ValueMember instead of DisplayMember?

I have a DGV that has 2 columns defined as DataGridViewComboBoxCell. One works fine but the other one doesn't. Both column are bound by a BindingSource. The only thing I can think of that is causing the one to act up. Both columns have the "autocomplete" property set to True.

In the column that acts up, whenever I selected a value from the dropdown either by selecting it with a mouse or typing a key and a value appears...as soon as I leave that column, instead of leaving the value in the column, it puts the ValueMember value in place of it. I have no idea why it would do that. My only conclusion would be the way that the SQL Query is structured. I'm using an UNION statement. Not sure about this!

Below is all the code for my DGV.

       
 Private Sub dgvTrans_CellMouseClick(sender As Object, e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles dgvTrans.CellMouseClick
        Try
            Select Case e.ColumnIndex
                Case 8
                    bs.AddNew()
                    bs.MoveLast()
                    dgvTrans.CurrentCell = dgvTrans.Rows(e.RowIndex + 1).Cells(3)
            End Select

        Catch ex As Exception
            Dim strErr As String = "frmTransactions/dgvTrans_CellMouseClick() - " & ex.Message
            MessageBox.Show(strErr, "User Notification", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub
    '
    '
    '
    '
    '
    '
    Private Sub dgvTrans_CellValueChanged(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvTrans.CellValueChanged
        Try
            If Not blnIsLoading Then
                Select Case e.ColumnIndex
                    Case 3
                        dgvTrans.Rows(e.RowIndex).Cells(4).Value = Now.Date
                End Select
            End If

        Catch ex As Exception
            Dim strErr As String = "frmTransactions/dgvTrans_CellValueChanged() - " & ex.Message
            MessageBox.Show(strErr, "User Notification", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub
    '
    '
    '
    '
    '
    '
    Private Sub dgvTrans_DataError(sender As Object, e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles dgvTrans.DataError
        Try

        Catch ex As Exception
            Dim strErr As String = "frmTransactions/dgvTrans_DataError() - " & ex.Message
            MessageBox.Show(strErr, "User Notification", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub
    '
    '
    '
    '
    '
    '
    Private Sub dgvTrans_KeyDown(sender As Object, e As System.Windows.Forms.KeyEventArgs) Handles dgvTrans.KeyDown
        Try
            Dim iRow As DataGridViewRow = dgvTrans.CurrentRow

            Select Case e.KeyCode
                Case 13     'Enter Key was pressed
                    bs.AddNew()                 'Add a new empty Row
                    bs.MoveLast()               'Puts the cursor in the Last Row
                    dgvTrans.CurrentCell = dgvTrans.Rows(iRow.Index + 1).Cells(3)    'Puts the focus on the 1st column
                Case 46     'Delete Key was pressed
                    bs.RemoveAt(iRow.Index)
                Case 120    'F9 Key was pressed
                    bs.AddNew()                 'Add a new empty Row
                    bs.MoveLast()               'Puts the cursor in the Last Row
                    dgvTrans.CurrentCell = dgvTrans.Rows(iRow.Index + 1).Cells(3)    'Puts the focus on the 1st column
            End Select

        Catch ex As Exception
            Dim strErr As String = "frmTransactions/dgvTrans_KeyDown() - " & ex.Message
            MessageBox.Show(strErr, "User Notification", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of BlakeMcKenna
BlakeMcKenna
Flag of United States of America image

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
Avatar of Netminder
Netminder

I've requested that this question be closed as follows:

Accepted answer: 0 points for BlakeMcKenna's comment #a39476318

for the following reason:

Starting closing process on behalf of Asker.

Netminder
Senior Admin