MDBのデータをDataGridViewに表示しています。
整数型の列があり、その列をCheckBoxで表示したいため
新たにCheckBoxの列を作成し、整数型の列の値を
Cell_FormattingイベントでCheckBoxに変換して整数型列を非表示にしています。
表示は出来たのですが、CheckBoxを変更したときに表示が現在のままとなってしまいます。
確認すると、●の箇所でCell_Formattingイベントに飛んでいました。
いろいろな所を探したのですが、解決しないため質問させて頂きます。
同じDataGridViewでほぼ同内容の物を表示させたいためCell_Formattingイベントに使用しました。
Private Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
Dim Cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=MDB保存場所.mdb")
Dim Sqlcm As OleDbCommand = Cn.CreateCommand
Dim Adapter As New OleDbDataAdapter(Sqlcm)
Dim Table As New DataTable
Sqlcm.CommandText = "SELECT * FROM テーブル①'"
Adapter.Fill(Table)
Dim チェックボックス列 As New DataGridViewCheckBoxColumn
DataGridView1.Columns.Add(チェックボックス列)
DataGridView1.DataSource = Table
Table.Dispose()
Adapter.Dispose()
Sqlcm.Dispose()
Cn.Dispose()
DataGridView.Columns(整数型列).Visible = False
End Sub
Private Sub DataGridView1_CellFormatting(sender As Object, e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting
'"00"なら☑にする
For i As Integer = 0 To DataGridView1.Rows.Count - 1
If CSng(DataGridView1(整数列, i).Value) = "00" Then
DataGridView1(0, i).Value = True
End If
Next i
End Sub
Private Sub DataGridView1_CellValidated(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellValidated
Dim dgv As DataGridView = DirectCast(sender, DataGridView)
If e.RowIndex = dgv.NewRowIndex OrElse Not dgv.IsCurrentRowDirty Then
Exit Sub
End If
cn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=MDB保存場所.mdb")
Dim NewData As String = ""
If dgv(e.ColumnIndex, e.RowIndex).Value Is DBNull.Value Then
Select Case e.ColumnIndex
Case 0
NewData = "00"
End Select
Else
Select Case e.ColumnIndex
Case 0
If dgv(e.ColumnIndex, e.RowIndex).Value = True Then
NewData = "00"
Else
NewData = "01"
End If
Case Else
NewData = dgv(e.ColumnIndex, e.RowIndex).Value
End Select
End If
Dim rs As New ADODB.Recordset
Dim com As String
com = String.Concat("select * from ", テーブル①, " where 主キー = '", DataGridView1(主キー列, e.RowIndex).FormattedValue, "'")
●rs.Open(com, cn, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockPessimistic)
With rs
If e.ColumnIndex = チェックボックス列 Then
.Update(dgv.Columns(整数型列).Name, newDat)
Else
.Update(dgv.Columns(e.ColumnIndex).Name, NewData)
End With
End Sub