編集: Winforms で次のコードを実行しようとしています。
私はxmlからデータを取得しています。それらは、作成したカスタムクラスを使用してデータグリッドビューに表示されます。すべての列をDataPropertyName
次の画像のように、datagridview の textboxes、buttoncolumn 、checkbox を datagrid に表示したいと思います。
次のイベントを使用して、追加したボタンの色を変更しています。dt
特定の要素について、グリッドの単一行にバインドしているとします。
if(dt.val=="true")
{
// change the color of that button
}
私は次のコードを使用しています。
private void Grid_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
{
DataGridViewColumn dt = Grid.Columns[9]; // 9 is column no
foreach (DataGridViewRow r in Grid.Rows)
{
if (newList[r.Index].val.ToString() == "true") //some condition
{
r.DefaultCellStyle = red; // this turns compete row red
// add something here to make button red of this row
}
else
{
r.DefaultCellStyle = green;
// add something here to make button red of this row
}
}
}
- 特定のセル ボタンの色を変更できません。
- すでに DataGridViewCheckboxColumn を追加していますが、デフォルトではグリッドに列が表示されていないため、最後の行にチェックボックスを追加するにはどうすればよいですか。