0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

WinForms DataGridViewのチェックボックスが反映されないときの小技

Posted at

はじめに

WinForms の DataGridView でチェックボックスの表示が思った通りにならない場合 の小技を紹介します。

解決の方法

画面上でチェックのON/OFFが正しく表示されないことがあります。

簡単な対処法として、「一度セルを編集不可にしてから、再度編集可能に戻す」という操作を行うと、チェックボックスの表示が正しくなります。

var row = dataGridView1.Rows[0];
row.Cells["選択"].ReadOnly = true;
row.Cells["選択"].ReadOnly = false;
  • 値自体は変わらない
  • 画面上の表示だけが更新されるイメージ

なぜこのトリックが必要なのか

  • DataGridView のチェックボックスセルは、イベント処理や操作の途中で描画がずれることがある
  • 編集可・不可を切り替えることで、内部的に再描画が行われ、チェック状態がUIに正しく反映される

おわりに

知らなかったのでしばらく悩まされました。
この小技を知っておけば、もう悩まされないですね。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?