i read the thread about Cascade ComboBox in DatagridView (VB.NET) in here.
http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/e7746ddf-3294-478c-a072-8a2eb83ba20c
I Configure the code in VB.net according to My Project...
I Give You Exactly My Code As it is..
DATAGRIDVIE = Flights_PrsonnelDatagridView
Two ComboBoxes (First In Column2 and Second In Column 3)
The Code Works Properly and i have a button Save that update the Flights_PersonnelTableAdapter..
The Data Saved Succesfully...
The Problem is that After Update Some Values Of the Filtered COmbobox dissapears although they were Stored in my SQL Table..
When I close the form and open it again the data of the filtered combobox are dislplayed Correctly..What is going on?
Private Sub Flights_PersonnelDataGridView_CellValueChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles Flights_PersonnelDataGridView.CellValueChanged
If e.ColumnIndex = FLPComboBoxColumn.Index Then
' clear the cell value of the territory column in the same row
If Me.Flights_PersonnelDataGridView.DataSource.[GetType]() Is GetType(DataTable) Then
Me.Flights_PersonnelDataGridView.Rows(e.RowIndex).Cells(CrewComboBoxColumn.Index).Value = DBNull.Value
' Else
' Me.Flights_PersonnelDataGridView.Rows(e.RowIndex).Cells(3).Value = Nothing
End If
End If
End Sub
Private Sub Flights_PersonnelDataGridView_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles Flights_PersonnelDataGridView.EditingControlShowing
If Me.Flights_PersonnelDataGridView.CurrentCell.ColumnIndex = CrewComboBoxColumn.Index Then
Dim control As DataGridViewComboBoxEditingControl = TryCast(e.Control, DataGridViewComboBoxEditingControl)
Dim bs As BindingSource = TryCast(control.DataSource, BindingSource)
If bs IsNot Nothing Then
' set the filteredChildBS as the DataSource of the editing control
TryCast(e.Control, ComboBox).DataSource = SelectAllPersonnel4CrewBindingSource
Dim Positionnvalue As Object = Me.Flights_PersonnelDataGridView.Rows(Me.Flights_PersonnelDataGridView.CurrentCell.RowIndex).Cells(FLPComboBoxColumn.Index).Value
If IsDBNull(Positionnvalue) OrElse Positionnvalue Is Nothing Then
SelectAllPersonnel4CrewBindingSource.Filter = "Key_positions=-1"
Else
SelectAllPersonnel4CrewBindingSource.Filter = "Key_positions=" & Positionnvalue.ToString()
End If
' set the SelectedValue property of the editing control
If Not IsDBNull(Me.Flights_PersonnelDataGridView.CurrentCell.Value) AndAlso Me.Flights_PersonnelDataGridView.CurrentCell.Value IsNot Nothing Then
control.SelectedValue = Me.Flights_PersonnelDataGridView.CurrentCell.Value
End If
End If
End If
End Sub
Private Sub Flights_PersonnelDataGridView_DataError(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs) Handles Flights_PersonnelDataGridView.DataError
If e.ColumnIndex <> CrewComboBoxColumn.Index Then
MessageBox.Show("Data error occurs:" & e.Exception.Message)
End If
End Sub