Reputation: 18202
EDIT: trying to excute the following code in Winforms.
I am fetching the data from xml & they are shown in the datagridview using custom class i have created.I have linked every column with DataPropertyName
I want to show datagridview textboxes, buttoncolumn , checkbox in datagrid like the following image.
I am using following event to change the color of the button i have added. For particular element, suppose i am binding dt
to the single row of grid, then
if(dt.val=="true")
{
// change the color of that button
}
i am using following code.
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
}
}
}
Upvotes: 2
Views: 3711
Reputation: 17875
You would change the background color of a specific cell like this:
r.Cells(9).Style.BackColor = Drawing.Color.Red
Upvotes: 2