i have a datagridview with 2 columns as combobox and i want to fill the second one depending on the first one.
Ex. I have a table in my database with stations
TableStations
Station 1
Station 2
And each stations has a different amount of outputs
Ex.
Station 1 Station 2
OutP1 OutP5
OutP2 OutP6
OutP7
What i want to do in the datagridview is that when the user selects from the first combobox a station the next combobox gets filled with the outputs for that station, my problem comes when the user adds a second row in the datagridview if he selects a diferent station the info in the first row will be modified.
Is there any solution for this or any other way to do what i want?
Thanks in advance
EDIT: this is the code im using
Con.Open()
cmd.Parameters.Clear()
With cmd
.CommandText = "Select output From List_outputs where station=@station"
.Parameters.AddWithValue("@station", datagridview1.Item(0, e.RowIndex).Value)
.Connection = Con
reader = .ExecuteReader
End With
combobox2.Items.Clear()
While reader.Read
combobox2.Items.Add(reader("output "))
End While
reader.Close()
This code is under the cellclick event of my datagridview.