DataGridView のカラムにチェックボックスを入れて、チェックボックスをクリックしたときにリアルタイムにDataGridViewの同一行等に対してスタイルを変更したり、カラムに書き込んだりする方法がやっとわかった。
要するにDataGridViewのCurrentCellDirtyStateChangedイベントで、チェックボックスを配置しているカラムのイベントを捉えて、コミットさせて、そのカラムの値を判定してチェックボックスの状態を取得すればいいわけねぇ。
{
string[] strItem = {"Desktop PC", "Note PC", "Tablet" };
for (int i = 0 ; i < strItem.Length; i++)
{
dataGridView1.Rows.Add();
dataGridView1["Column2", i].Value = strItem[i];
}
}
private void dataGridView1_CurrentCellDirtyStateChanged(object sender, EventArgs e)
{
if (dataGridView1.CurrentCellAddress.X == 0 && dataGridView1.IsCurrentCellDirty)
{
// — Commit!
dataGridView1.CommitEdit(DataGridViewDataErrorContexts.Commit);
if (dataGridView1["Column1",
dataGridView1.CurrentCellAddress.Y].Value.ToString() == "True")
{
for (int i = 0; i < dataGridView1.Columns.Count; i++)
{
dataGridView1[i, dataGridView1.CurrentCellAddress.Y].Style.BackColor = Color.Red;
}
dataGridView1["Column3", dataGridView1.CurrentCellAddress.Y].Value = "購入";
}
else
{
for (int i = 0; i < dataGridView1.Columns.Count; i++)
{
dataGridView1[i, dataGridView1.CurrentCellAddress.Y].Style.BackColor = Color.White;
}
dataGridView1["Column3", dataGridView1.CurrentCellAddress.Y].Value = null;
}
}
}
Unquestionably believe that which you said. Your favourite justification appeared to be at the internet the easiest factor to take into account of.
I say to you, I certainly get irked while other folks think about issues that they plainly do not recognize about.
You controlled to hit the nail upon the top as neatly as outlined out
the whole thing without having side-effects , other people can take a signal.
Will probably be again to get more. Thanks! http://www.gaycockboys.com/video/free-brokestraightboys-videos-J9KLzgWmE07.html
I couldn’t resist commenting. Exceptionally well written! http://www.yahoo.net
This is a topic that is near to my heart… Many thanks! Exactly where are your contact details though? http://bing.net
Thhis is a very good tip esoecially to those new to the blogosphere.
Short but verfy precise information… Thanks for sharing this one.
A must read post!