Reputation: 1390
I'm creating an ordering system for booking customers in, and I want a combobox in a datagridview to be able to mark a certain job as complete, and change the colour of that row to green when yes is selected, I'd like some help with this please as I have no idea how to do it, I have looked all over the internet and found nothing.
this is a screenshot of the database, any and all help would be greatly appreciated.
I'm using WinForms
thanks in advance
Upvotes: 0
Views: 2174
Reputation: 17590
You have to use CellValueChanged
event.
private void GridCellValueChanged(object sender, DataGridViewCellEventArgs e)
{
//just to be safe
if (e.RowIndex < 0 || e.ColumnIndex < 0)
{
return;
}
var value = dataGridView1[e.ColumnIndex, e.RowIndex].Value;
if (value != null && value.ToString() == "Yes") // is completed
{
dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Green;
}
else
{
dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.White;
}
}
hope it helps :)
Upvotes: 3
Reputation: 32671
You should use Datagridview value changed event. And in that event get the selected row and cell value. Based on that value you should set the selected row backcolor.
Upvotes: 0