I am using vb.net visual studio 2010
I have two comboboxes in the datagrid - one for Country and the other for State Province.
Obviously the Country combo box controls what state/provinces to display.
The trouble for rows with different countries - when the user is changing the state for one country - the other states remain blank until the user sets focus somewhere else - if they don't it looks like the state information on the grid has vanished
what to do?
''' <summary>
''' http://www.daniweb.com/software-development/csharp/threads/80084
''' http://bytes.com/topic/visual-basic-net/answers/660909-get-value-cell-datagridview
''' http://www.java2s.com/Code/VB/Database-ADO.net/UseFiltertofilterDataTable.htm
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub addressDataGridView_CellBeginEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellCancelEventArgs) Handles addressDataGridView.CellBeginEdit
If addressDataGridView.Columns(e.ColumnIndex).Name = "stprv_cd" Then
Dim dt As New DataTable
dt = ds2.Tables("stateprv").Clone
' 2. Set display filter
Dim filter1 As String = "rel_id = 'CA'" ' addressDataGridView.Item("cntry_cd", e.RowIndex).Value.ToString
Select Case addressDataGridView.Item("cntry_cd", e.RowIndex).Value.ToString
Case "CA", "US"
filter1 = "rel_id = '" & addressDataGridView.Item("cntry_cd", e.RowIndex).Value.ToString & "'"
Case Else
filter1 = "rel_id = ' '"
End Select
' 3. Set sort
Dim sort1 As String = "display"
dt = ds2.Tables("stateprv").Select(filter1, sort1).CopyToDataTable
Dim col As DataGridViewComboBoxColumn
col = CType(addressDataGridView.Columns("stprv_cd"), DataGridViewComboBoxColumn)
col.DataSource = dt
col.DisplayMember = "display"
col.ValueMember = "value"
End If
End Sub
''' <summary>
''' http://www.vbdotnetforums.com/winforms-grids/11313-setting-cell-focus-datagridview.html
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub addressDataGridView_CellEndEdit(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles addressDataGridView.CellEndEdit
If addressDataGridView.Columns(e.ColumnIndex).Name = "stprv_cd" Then
'needed because initial retreive did not fire country combo box to load state
' lookupstprvBindingSource.DataSource = lookupcountryBindingSource
' lookupstprvBindingSource.DataMember = "CSP"
Dim dt As New DataTable
dt = ds2.Tables("stateprv").Copy
Dim col As DataGridViewComboBoxColumn
col = CType(addressDataGridView.Columns("stprv_cd"), DataGridViewComboBoxColumn)
col.DataSource = dt
col.DisplayMember = "display"
col.ValueMember = "value"
End If
End Sub