Results 1 to 3 of 3

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

  1. #1
    Slabs1960 is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.5
    Join Date
    Mar 2017
    Posts
    3
    Reputation
    0

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

    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).

    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.

    Code:
    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
    
    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
    
    
            txtAperture.Text = sAperture
    
            txtFocalLength.Text = sFocalLength
    
    
        End Sub
    Last edited by Slabs1960; 03-19-2017 at 12:22 PM.

  2. #2
    jmcilhinney's Avatar
    jmcilhinney is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    13,815
    Reputation
    1707
    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.

  3. #3
    Slabs1960 is offline VB.NET Forum Newbie
    .NET Framework
    .NET 4.5
    Join Date
    Mar 2017
    Posts
    3
    Reputation
    0
    I got it, thanks. Working now.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •