Conditional Formatting for DataGridViewColumns and Cells

0
0

Hello,

I want to ask if there is anything like “Conditional Formatting” for the columns of the DataGridView-control.  For example, when the value of a certain column is false, the background color for this cell in that column should be red. And is it possible to highlight the text in the cells, e.g. I have a TextBox where the user can enter a search term and then all cells of the DataGridView should highlight the part matching the search term yellow and the rest of the text should stay black.

 

Best,

Marcel

 

 

  • You must to post comments
0
0

Thanks Luca,

this helped a lot. But I still have one question concerning the text highlighting. In our project we have a read-only DataGridView which displays customer data. And there is also a separate TextBox for the user to enter a search term and a Button to start the search. I took the code from “dataGridView2_CellValueChanged“-event from your example project and added it to the CellFormatting-event of our DataGridView, customized it, so it takes the text to highlight from our separate textbox and run the project.

Unfortunately not all rows a displayed correctly and if I enter a new search term the DataGridView does not highlight the new text, alltough the code runs through the event as I checked in debug mode. Any idea what I am missing?

 

Best,

Marcel

  • Luca (ITG)
    Any chance you can isolate that in a small test case?
  • You must to post comments
0
0

You can change the style of any cell either by changing the properties of the Style member, or assigning a new Style object or handling the CellFormatting event. To highlight or format the text inside a cell you can use html markup and set the AllowHtml property of the column to true.

See attached sample, shows two different approaches.

HTH

/Luca

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.