locked
Visual Basic 2010 and Database with dropdown list

    Question

  • I hope that anybody could help me with this.

    I linked the table (Arvutid) to the program in DataSet with TableAdapter. I got the Nimi column in a dropdown box, but I need to be able to link the dropdown box with the database and labels for the IP and Kirjeldus column so that when I select a name from the dropdown box, then automatically the Label values would also change respectfully.

    This is my code so far:

    Public Class Data
    
      Private Sub Data_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Disposed
        End
      End Sub
    
      Private Sub Data_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'ArvutidDataSet.Andmed' table. You can move, or remove it, as needed.
        Me.AndmedTableAdapter.Fill(Me.ArvutidDataSet.Andmed)
        'TODO: This line of code loads data into the 'ArvutidDataSet.Andmed' table. You can move, or remove it, as needed.
        Me.AndmedTableAdapter.Fill(Me.ArvutidDataSet.Andmed)
        'TODO: This line of code loads data into the 'ArvutidDataSet.Andmed' table. You can move, or remove it, as needed.
        Me.AndmedTableAdapter.Fill(Me.ArvutidDataSet.Andmed)
    
      End Sub
    
      Private Sub AndmedBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Validate()
        Me.AndmedBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.ArvutidDataSet)
    
      End Sub
    
      Private Sub AndmedBindingNavigatorSaveItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AndmedBindingNavigatorSaveItem.Click
        Me.Validate()
        Me.AndmedBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.ArvutidDataSet)
    
      End Sub
    
      Private Sub cmbNim_DropDownClosed(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbNim.DropDownClosed
        Dim xx As Integer
        xx = Val(cmbNim.SelectedIndex)
        Label1.Text = xx
        IPLabel1.Text = Str(AndmedTableAdapter.GetData)
      End Sub
    End Class
    

    Monday, September 27, 2010 9:32 AM

Answers

  • if you bind the Labels to the same bindingsource as the bindingnavigator and the combobox, whenever you change the selection with the navigator or combobox, the labels will update also.

    something like this:

    ComboBox1.DataSource = AndmedBindingSource
        ComboBox1.DisplayMember = "Nimi"
    
        Label1.DataBindings.Add(New Binding("Text", AndmedBindingSource, "IP"))
        Label2.DataBindings.Add(New Binding("Text", AndmedBindingSource, "Kirjeldus"))
    
    Monday, September 27, 2010 3:14 PM