バインディング ソースにデータ バインドされた DataGridView を使用します。さらに、ユーザーの左端に CheckBoxCol を 1 つ作成します。そこにチェックボックスを入れて並べ替えると、すべてのチェックが消えます。それを回避する方法を知っている人はいますか?
ここにいくつかのコードがあるので、同じページにいます;):
dtZg_Betr = new DataTable(); // DataTable object
// [...] SQL SELECT and so on, I cut that stuff a bit
adapter.Fill(dtZg_Betr); // OleDbAdapter -> fill the table with the SQL SELECT results
// [...]
bsZg_Betrn = new BindingSource(); // BindingSource object
bsZg_Betrn.DataSource = dtZg_Betr;
dgvZg_Betr.DataSource = bsZg_Betr; // bind data to DataGridView
DataGridViewCheckBoxColumn dgvCheckBox = new DataGridViewCheckBoxColumn();
dgvZg_Betr.Columns.Insert(0, (DataGridViewColumn)dgvCheckBox); // add additional checkbox column
// Later on somewhere else:
adapter.Update(dtZg_Betr); // OleDbAdapter -> update DB with table's changes
DataGridView には、入力するコード自体はありません。後でもちろんチェックボックスのクリックなどは処理されますが、問題には関係ありません。
よろしくお願いします!