How do I Return a Value from a DataSet after a ComboBox Selection

Slabs1960

Member
Joined
Mar 19, 2017
Messages
19
Programming Experience
10+
Hi. I am new to the Forum and new to VB.Net. I have had extensive programming with VBA Excel and other proprietary software (PLC & Scada in the Automation fields). :wavey:

My problem is as follows:

I have a Windows Form Application. I have created a XML DataSet, which has a table in it. This table has four columns. Column A is the Id column (unique key). Column B is a name column an is also has a unique value. The other columns have normal string data in them. I have a form on which I have created a ComboBox that is populated from column A. This all works as it should.

When an item is selected in the ComboBox, I would like to return the associated value from Column B into TextBox 1, Column C value into TextBox 2, etc.

Any assistance would be appreciated.

VB.NET:
[SIZE=2]Private xmlFormDataPath As String = My.Application.Info.DirectoryPath & "xmlAstroData.xml"
    Private Sub frmOTOParameters_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        DsFormData.ReadXml(xmlFormDataPath)
        'Clear Form Data
        cbOTAName.Items.Clear()
        txtAperture.Text = ""
        txtFocalLength.Text = ""
        txtFocalRatio.Text = ""
        cbEyepieceName.Items.Clear()
        txtEyepieceMM.Text = ""
        txtAFOV.Text = ""
        cbBarlowMag.Items.Clear()
        cbFocalReducer.Items.Clear()
        'Populate OTA Name Combobox List
        cbOTAName.DataSource = DsFormData.Tables("tblOTAData")
        cbOTAName.DisplayMember = DsFormData.Tables("tblOTAData").Columns("otaName").ColumnName
        cbOTAName.Text = "Select from....."

        'Populate Eyepiece Name Combobox List
        cbEyepieceName.Items.Clear()
        cbEyepieceName.DataSource = DsFormData.Tables("tblEyePieces")
        cbEyepieceName.DisplayMember = DsFormData.Tables("tblEyePieces").Columns("eypieceName").ColumnName
        cbEyepieceName.Text = "Select from....."
    End Sub

[I]Private Sub cbOTAName_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cbOTAName.SelectedIndexChanged
        Dim sOTAName As String = ""
        Dim sAperture As String = ""
        Dim sFocalLength As String = ""
        Dim sTempValue As String

        sOTAName = cbOTAName.Text

        For Each row As DataRow In DsFormData.tblOTAData.Rows

            sTempValue = DsFormData.ReadXml(xmlFormDataPath) 'Column Name ??????
            MessageBox.Show(sTempValue)

        Next row
[/I]

        txtAperture.Text = sAperture

        txtFocalLength.Text = sFocalLength


    End Sub[/SIZE]
 
Last edited:
You don't need any code when the selection is made. Simply bind the TextBoxes to the same source as the ComboBox, e.g.
With myComboBox
    .ValueMember = "ID"
    .DisplayMember = "Name"
    .DataSource = myDataTable
End With

myTextBox.DataBindings.Add("Text", myDataTable, "Description")
After that, the user can select from a list of Name values in the ComboBox and then the corresponding Description value will be displayed in the TextBox.
 
Back
Top