troubleshooting Question

Datagridview combo display member

Avatar of pdi656
pdi656 asked on
.NET ProgrammingVisual Basic.NET
8 Comments1 Solution329 ViewsLast Modified:
I'm attempting to fill a combo box in a windows form datagridview. I am having issues with the value member and display member. The field in the datagridview holds an ID number (Request_Type). When I load the combobox values, I expect the datagridview to display the Description (Display member), but the Request_Type ID still shows up. I've been messing with this for a few hours and still can't figure it out. Any ideas?

   Private Sub frmMaintain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Load_Datagrids()
    End Sub

'----------------------------------------------------------------------------------------
 Private Sub Load_Datagrids()
        Dim cn As New SqlConnection(CS)
        Dim cmd As New SqlCommand
        Dim rst1 As SqlDataReader
        Dim strSQL As String

        Try
            cn.Open()

            strSQL = "SELECT TOP (100) Percent Action_Type_ID, Action_Description, Request_Type" & _
                     " FROM tblAction_Type" & _
                     " ORDER BY Action_Description"

            cmd = New SqlCommand(strSQL, cn)
            rst1 = cmd.ExecuteReader()
            dtActions.Clear()
            dtActions.Load(rst1)
            dgvActions.AutoGenerateColumns = False
            rst1.Close()

            'Adjusts the columns dgvActions
            For Each col As DataGridViewColumn In dgvActions.Columns
                Select Case col.Name
                    Case Is = "Request_Type"
                        Dim colCbo As DataGridViewComboBoxColumn
                        colCbo = dgvActions.Columns("Request_Type")
                        colCbo.ValueMember = "Request_Type_ID"
                        colCbo.DisplayMember = "Description"
                        colCbo.DataSource = Get_Combo_Data(1)
			colCbo.DataPropertyName= "Request_Type"
                End Select
            Next col
            dgvActions.DataSource = dtActions
       

        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            cmd = Nothing
            rst1 = Nothing
            If cn.State = ConnectionState.Open Then
                cn.Close()
            End If
            cn.Dispose()
        End Try
    End Sub

'----------------------------------------------------------------------------------------
 Private Function Get_Combo_Data(ByVal byIn As Byte) As DataView
        Dim cn As New SqlConnection(CS)
        Dim cmd As New SqlCommand
        Dim rst1 As SqlDataReader
        Dim strSQL As String
        Dim dtTmp As DataTable
        Dim ds As New DataSet
        Dim dv As New DataView


        'This function will get the data required for the combo lookups
        Try
            cn.Open()

            Select Case byIn

                Case Is = 1
                    'Requset Types
                    strSQL = "SELECT TOP (100) Percent Request_Type_ID, Description" & _
                             " FROM tblRequest_Type" & _
                             " ORDER BY Description"
            End Select

            cmd = New SqlCommand(strSQL, cn)
            rst1 = cmd.ExecuteReader()
            dtTmp = New DataTable("Temp") 'Define a new temp datatable
            dtTmp.Load(rst1) 'Load the data into a temp datatable
            ds.Tables.Add(dtTmp)

            dv.Table = ds.Tables("Temp").Copy

            Get_Combo_Data = dv


        Catch ex As Exception
            MsgBox(ex.Message)
        Finally
            cmd = Nothing
            rst1 = Nothing
            If cn.State = ConnectionState.Open Then
                cn.Close()
            End If
            cn.Dispose()
            dtTmp = Nothing
            ds = Nothing
        End Try


    End Function
'----------------------------------------------------------------------------------------
ASKER CERTIFIED SOLUTION
pdi656

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros