Hello: I have an unbound datagridview and a seperate dropdown outside of the grid. When the user makes a selection from this dropdown, I would like to filter on their selection in order to repopulate my grid. I searched through all the postings in the forum but only found one post similar...however it had to do with a bound datagrid.
All my cells in the datagrid are of DataGridViewComboBoxColumn type.
OnChange of my drop-down ...I've started this code:
'onChange on my drop-down:
Private Sub cboProfiles_SelectionChangeCommitted(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboProfiles.SelectionChangeCommitted
If Not IsNothing(cboProfiles.SelectedValue) Then
Dim sql As String = ""
sql = "SELECT tblProfileName.ProfileId, tblProfileName.ProfileName, tblStates.StateId,tblStates.StateName, tblStates.Zone1, tblStates.Color1, tblStates.Brightness1,tblStates.Flash1, tblStates.Zone2, tblStates.Color2, tblStates.Brightness2,tblStates.Flash2, tblStates.Zone3, tblStates.Color3, tblStates.Brightness3, tblStates.Flash3, tblStates.Zone4, tblStates.Color4, tblStates.Brightness4,tblStates.Flash4, tblStates.SpeedId, tblStates.Wheel FROM tblProfileName,tblStates where tblProfileName.ProfileId = tblStates.ProfileId and tblStates.ProfileId" & cboProfiles.SelectedValue.ToString()
Dim myDB As New OleDb.OleDbConnection(sConnectionString)
Dim myDA As New OleDb.OleDbDataAdapter("SELECT tblProfileName.ProfileId, tblProfileName.ProfileName, tblStates.StateId,tblStates.StateName, tblStates.Zone1, tblStates.Color1, tblStates.Brightness1,tblStates.Flash1, tblStates.Zone2, tblStates.Color2, tblStates.Brightness2,tblStates.Flash2, tblStates.Zone3, tblStates.Color3, tblStates.Brightness3, tblStates.Flash3, tblStates.Zone4, tblStates.Color4, tblStates.Brightness4,tblStates.Flash4, tblStates.SpeedId, tblStates.Wheel FROM tblProfileName,tblStates where tblProfileName.ProfileId = tblStates.ProfileId and tblStates.ProfileId=" & cboProfiles.SelectedValue.ToString(), myDB)
Dim myDS As New Data.DataSet
Dim myDR As Data.DataRow
Try
myDA.Fill(myDS, "profiles")
Dim profiles As DataTable
profiles = myDS.Tables("profiles")
If profiles.Rows.Count = 1 Then
'first, populate other textboxes that are not in the grid
For Each myDR In profiles.Rows
txtZone1.Text = myDR("Zone1")
txtZone2.Text = myDR("Zone2")
txtZone3.Text = myDR("Zone3")
txtZone4.Text = myDR("Zone4")
txtState1.Text = myDR("Statename")
'now, populate the grid...for now, just trying to just get one of my cells (DataGridViewComboBoxColumn) to set it's selected index to value from filtered ds:
With Me.DataGridView1.Rows
Dim cbn As DataGridViewComboBoxColumn = DataGridView1.Columns(0)
With cbn
.ValueMember = myDR("Color1")
End With
End With
Next
End If
myDB.Close()
Catch
MsgBox("An error occurred")
End Try
Else
End If
End Sub
Can anyone point me in the right dirrection? I'm just not sure how to set the value for my DataGridViewComboBoxColumn
controls in the grid.
Thank you for your help,
annarene
All my cells in the datagrid are of DataGridViewComboBoxColumn type.
OnChange of my drop-down ...I've started this code:
'onChange on my drop-down:
Private Sub cboProfiles_SelectionChangeCommitted(ByVal sender As Object, ByVal e As System.EventArgs) Handles cboProfiles.SelectionChangeCommitted
If Not IsNothing(cboProfiles.SelectedValue) Then
Dim sql As String = ""
sql = "SELECT tblProfileName.ProfileId, tblProfileName.ProfileName, tblStates.StateId,tblStates.StateName, tblStates.Zone1, tblStates.Color1, tblStates.Brightness1,tblStates.Flash1, tblStates.Zone2, tblStates.Color2, tblStates.Brightness2,tblStates.Flash2, tblStates.Zone3, tblStates.Color3, tblStates.Brightness3, tblStates.Flash3, tblStates.Zone4, tblStates.Color4, tblStates.Brightness4,tblStates.Flash4, tblStates.SpeedId, tblStates.Wheel FROM tblProfileName,tblStates where tblProfileName.ProfileId = tblStates.ProfileId and tblStates.ProfileId" & cboProfiles.SelectedValue.ToString()
Dim myDB As New OleDb.OleDbConnection(sConnectionString)
Dim myDA As New OleDb.OleDbDataAdapter("SELECT tblProfileName.ProfileId, tblProfileName.ProfileName, tblStates.StateId,tblStates.StateName, tblStates.Zone1, tblStates.Color1, tblStates.Brightness1,tblStates.Flash1, tblStates.Zone2, tblStates.Color2, tblStates.Brightness2,tblStates.Flash2, tblStates.Zone3, tblStates.Color3, tblStates.Brightness3, tblStates.Flash3, tblStates.Zone4, tblStates.Color4, tblStates.Brightness4,tblStates.Flash4, tblStates.SpeedId, tblStates.Wheel FROM tblProfileName,tblStates where tblProfileName.ProfileId = tblStates.ProfileId and tblStates.ProfileId=" & cboProfiles.SelectedValue.ToString(), myDB)
Dim myDS As New Data.DataSet
Dim myDR As Data.DataRow
Try
myDA.Fill(myDS, "profiles")
Dim profiles As DataTable
profiles = myDS.Tables("profiles")
If profiles.Rows.Count = 1 Then
'first, populate other textboxes that are not in the grid
For Each myDR In profiles.Rows
txtZone1.Text = myDR("Zone1")
txtZone2.Text = myDR("Zone2")
txtZone3.Text = myDR("Zone3")
txtZone4.Text = myDR("Zone4")
txtState1.Text = myDR("Statename")
'now, populate the grid...for now, just trying to just get one of my cells (DataGridViewComboBoxColumn) to set it's selected index to value from filtered ds:
With Me.DataGridView1.Rows
Dim cbn As DataGridViewComboBoxColumn = DataGridView1.Columns(0)
With cbn
.ValueMember = myDR("Color1")
End With
End With
Next
End If
myDB.Close()
Catch
MsgBox("An error occurred")
End Try
Else
End If
End Sub
Can anyone point me in the right dirrection? I'm just not sure how to set the value for my DataGridViewComboBoxColumn
controls in the grid.
Thank you for your help,
annarene