質問者
データバインドされた Windows フォーム DataGridView コントロールに非バインド列(テキスト列)を追加する

質問
-
オンラインヘルプを参考に非バインド列(テキスト)を追加してみようとしましたが
実行エラーが発生しましたPublic Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
mdb_file_台帳 = "\\--台帳.mdb"
provider_台帳 = "Provider=--"
provider_台帳 += mdb_file_台帳Dim CommandText As String
'SQLのSELECT文を作成
CommandText = "SELECT * FROM T001台帳"'以上の設定からデータアダプターを生成
Dim Adapter As New System.Data.OleDb.OleDbDataAdapter
Adapter = New System.Data.OleDb.OleDbDataAdapter(CommandText, provider_台帳)'▼データ読込
Dim Table As New DataTable()
Adapter.Fill(Table)'▼DataGridViewにデータを表示
Dim BindingSource1 As New BindingSource
BindingSource1.DataSource = Table
DataGridView1.DataSource = BindingSource1'▼ボタン列を追加
Dim ButtonColumn As New DataGridViewButtonColumn
With ButtonColumn
.Name = "詳細" '列の名前。プログラム中で使用する。
.HeaderText = "詳細" '列の見出しに表示するテキスト
.Text = "詳細" 'ボタンに表示するテキスト
.UseColumnTextForButtonValue = True
End With
DataGridView1.Columns.Insert(0, ButtonColumn)'--------------追加 start----------------
’テキスト列
Dim add_column As New DataGridViewColumn
With add_column
.Name = "add"
.HeaderText = "add"
End With
' DataGridView1.Columns.Insert(2, add_column) <---error'--------------追加 end----------------
End Sub
End Class
エラー内容は
InvalidOpretionException はハンドルされませんでした
列の CellType プロパティが null であるため、列を追加することはできません。サンプルのコマンドボタンは正常に表示されます
いろいろ調べましたが、解決できません
ご指導お願い致します。また、もし御存知でしたら、チェックボックスの追加もご教授ください。