Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > Change ForeColor based on a value
 

Change ForeColor based on a value

I have a datagrid on a windows form. it has 1 column. The values in this column is either True or False. I wish to set the forecolor to red when the value is True.

Can this be done?
CSDeveloper  Wednesday, November 16, 2005 12:28 AM
Actually you should use the CellFormatting event, not CellPainting. Here is a sample in the help: http://msdn2.microsoft.com/en-us/library/z1cc356h.aspx

-mark
DataGridView Program Manager
Microsoft
This post is provided "as-is"
Mark Rideout  Wednesday, November 16, 2005 10:48 PM
Yes .

Use the Cellpainting event in a Datagrid View.


private void dgv_childList_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)

{

if (e.ColumnIndex == 0)

{

if (e.Value.ToString() == "ADO.NET")

{

e.CellStyle.ForeColor = Color.Red;

}

}

}


 



That is .NET 2 ? Do you need 1.1 ? I think if I remeber writely you need to override a DataGridTextBoxColumn and the paint commands. Have an example if you need one ?

James

James Knowles  Wednesday, November 16, 2005 2:28 PM
Actually you should use the CellFormatting event, not CellPainting. Here is a sample in the help: http://msdn2.microsoft.com/en-us/library/z1cc356h.aspx

-mark
DataGridView Program Manager
Microsoft
This post is provided "as-is"
Mark Rideout  Wednesday, November 16, 2005 10:48 PM
;-)

You live and learn . Thanks Mark ;-) I will change our datagridview's

James
James Knowles  Wednesday, November 16, 2005 11:59 PM

You can use google to search for other answers

Custom Search

More Threads

• Problem with DataGridView ComboBox implementation
• How to get top 10 rows of data in a datagrid
• listview in window form
• Check row update for DataGridView in VB.net
• How to disable the automatic resize of column headers in listview?
• IIS: Server Application Unavailable for aspx
• DataGridView -Sort image columns
• databound listbox
• dropdownlist control default
• MustInherit