user3787881
user3787881

Reputation:

How to populate a gridLookUp control from a dataset in VB.Net

I use VB.Net and SQL Server 2008. I would like to know how to populate GridLookUp control with data from my DataSet. When I pass query in SQL it executes successfully, which means it is not a problem with stored procedures. Have I missed something? See my example.

txtStateGather.EditValue is the name of my GridLookUp control - DevExpress control

Private txtGatherLoaded As Boolean
Private gatherDs = New DataSet

Private Function GatherLoad()
    Try
        con.Close()
        con.Open()
        gatherDs = New Data.DataSet

        If txtGatherLoaded = False Then
            com = New SqlCommand("EXECUTE basicGatherSelect '" & txtStateID.Text & "','" & txtName.Text & "'", con)
            adp.SelectCommand = com
            adp.Fill(gatherDs)

            adp.dispose()
            com.Dispose()



            txtStateGather.Properties.DisplayMember = gatherDs.Tables(0).Columns(0).Caption.ToString
            txtStateGather.Properties.ValueMember = gatherDs.Tables(0).Columns(0).Caption.ToString
            txtStateGather.Properties.AutoComplete = True
            txtGatherLoaded = True

        End If

        If txtStateGather.EditValue Is Nothing Or txtStateGather.EditValue Is "" Or txtStateGather.EditValue Is System.DBNull.Value Or txtStateGather.Text = "" Then

            txtStateGather.EditValue = ""


        Else

            Dim rowHandle As System.Data.DataRowView
            rowHandle = txtStateGather.Properties.GetRowByKeyValue(txtStateGather.EditValue)
            txtStateGather.EditValue = rowHandle.Item(0).ToString
            txtStateGatherName.Text = rowHandle.Item(1).ToString
        End If

    Catch ex As Exception
        MessageBox.Show(ex.Message)

    Finally
        con.Close()



    End Try
End Function

Upvotes: 0

Views: 183

Answers (1)

LarsTech
LarsTech

Reputation: 81655

It doesn't look like you set the DataSource anywhere in your code:

txtStateGather.Properties.DisplayMember = gatherDs.Tables(0).Columns(0).Caption.ToString
txtStateGather.Properties.ValueMember = gatherDs.Tables(0).Columns(0).Caption.ToString
txtStateGather.Properties.DataSource = gatherDs.Tables(0)

Upvotes: 1

Related Questions