DataTable
에 바인딩 된 DataGridView
이 데이터베이스에서 채워집니다.DataGridView DataError가 첫 번째 행에서 throw되지 않았습니다.
Dim ComboBoxData As ArrayList = New ArrayList(New String() {"",
"Default",
"User-set"})
Dim ComboBoxBS As BindingSource = New BindingSource
ComboBoxBS.DataSource = ComboBoxData
SomeDataGridViewComboBoxColumn.DataSource = ComboBoxBS
나는 DataTable
의 필드가 ComboBoxData
에 정의 된 이외의 값을 가질 수 있도록하려면이 그리드, 난과 같이 ArrayList
의 결합 데이터 DataGridViewComboBoxColumn
s의 몇 가지있다. 이것은 내가 DataError
이벤트를 처리하고 ComboBox
에 누락 된 값을 추가하여 수행 한 :
Private Sub grid_DataError(ByVal sender As System.Object,
ByVal e As System.Windows.Forms.DataGridViewDataErrorEventArgs
) Handles grid.DataError
If TypeOf grid.Columns(e.ColumnIndex) Is DataGridViewComboBoxColumn Then
Dim value = grid.Rows(e.RowIndex).Cell(e.ColumnIndex).Value
Dim cboCol As DataGridViewComboBoxColumn = CType(grdDataGrid2.Columns(e.ColumnIndex), DataGridViewComboBoxColumn)
Dim bs As BindingSource = CType(cboCol.DataSource, BindingSource)
If Not bs.Contains(value) Then
bs.Add(value)
bs.Position = bs.IndexOf(value)
End If
e.Cancel = False
Return
End If
End Sub
이 첫 번째 제외한 모든 행에 대해 작동합니다. 디버깅을 통해 DataError
이벤트가 실제로 첫 번째 행에 대해 실행되지 않음을 확인했습니다. 그러나 "기준 표현식의 데이터 유형 불일치"라는 행 헤더에 빨간색 느낌표가 있습니다.
왜 첫 번째 행이 나머지로 동작하지 않습니까? 이 문제에 대한 더 나은 접근법을 제안하십시오.
확실치 않지만 모든 테이블의 첫 번째 행은 대부분 헤더 행입니다. 그게 뭔가를 일으킬 수는 없습니까? – Terry
나는 체크했다. 첫 번째 행 (인덱스 0)은 헤더가 아닌 데이터가있는 첫 번째 행입니다. – joharei