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.
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?
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.
Please login first to submit.