Using Values from Comboboxes in a Datagid?

  • Thread starter Thread starter Rocky48
  • Start date Start date
R

Rocky48

Guest
Instead of the message box code I now want to use the SelectedValue from each combobox.

I have tried this but it does not work:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'MsgBox($"{ComboBox1.SelectedValue} -- {ComboBox1.Text} / {ComboBox2.SelectedValue} -- {ComboBox2.Text}")
Dim sql As String = Nothing
Dim cboVal1 As Integer
Dim cboVal2 As Integer
cboVal1 = ComboBox1.SelectedValue
cboVal2 = ComboBox2.SelectedValue

Using connection As New SqlConnection(connectionString)
connection.Open()
sql = "Select VID, EVENT, Event_Sub from Verse WHERE (Event= @cboVal1 AND Event_Sub=@cboVal2)"
End Using

The previous Sub routine fills the comboboxes:

Private Sub frmSecond_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'Verses_FindDataSet3.Verse' table. You can move, or remove it, as needed.
Me.VerseTableAdapter.Fill(Me.Verses_FindDataSet3.Verse)
Dim sql As String = Nothing
Dim ds As New DataSet()
Dim stepInfo As String = String.Empty
Try
stepInfo = "Step: instatiate connection"
Using connection As New SqlConnection(connectionString)
stepInfo = "Step: test open connection"
connection.Open()
stepInfo = "Step: load first data"
sql = "Select SID, EVENT from Event_Type"
Using adaptor As New SqlDataAdapter(sql, connection)
adaptor.Fill(ds, "Tab_Event_Type")
End Using
stepInfo = "Step: load second data"
sql = "Select BID, SUBEVENT from Sub_Event"
Using adaptor As New SqlDataAdapter(sql, connection)
adaptor.Fill(ds, "Tab_Sub_Event")
End Using
End Using
stepInfo = "Step: bind first combobox"
ComboBox1.DataSource = ds.Tables("Tab_Event_Type")
ComboBox1.ValueMember = "SID"
ComboBox1.DisplayMember = "Event"
stepInfo = "Step: bind second combobox"
ComboBox2.DataSource = ds.Tables("Tab_Sub_Event")
ComboBox2.ValueMember = "BID"
ComboBox2.DisplayMember = "Event_Sub"
Catch ex As Exception
MessageBox.Show($"Error: {stepInfo}{vbNewLine}{ex.ToString}")
End Try
End Sub

I need the SID and BID values as the Verse table saves the values of the ID columns to select type of verse required.

Your help would be appreciated!

Continue reading...
 
Back
Top