When I click on the column in Datagrdiview, I want to disable the highlighted color that appears in the S.No field which was seen in the image. I couldn't find any settings in Visual Studio. I numbered the 1st row with RowPostPaint. How can I make this area with the same color as the selected row?

Mehmet FatihPosted Apr 25, 2024, 12:07 PM
I have solved with the settings of visual studio.
Mehmet FatihPosted Apr 25, 2024, 7:21 AM
I tried both of them but nothing has chnaged.
Naimish MakwanaPosted Apr 25, 2024, 6:15 AM
You can achieve this by handling the
CellFormattingevent of the DataGridView. In this event, you can check if the cell in the first column is selected and then change its style. Here’s an example:In this code,
dataGridView1is the DataGridView control. TheCellFormattingevent is fired every time a cell is painted. In the event handler, we check if the cell is in the first column (the S.No column). If it is, we set theSelectionBackColorandSelectionForeColorof the cell style to the normal back color and fore color of the cell. This will make the cell appear the same whether it is selected or not.You can wire up the event in the form’s constructor or the
Loadevent like this:Please replace
dataGridView1with the actual name of your DataGridView control. Also, adjust the column index if your S.No column is not the first column. The column indices are 0-based, so the first column is 0, the second column is 1, and so on.Thanks
Jayraj ChhayaPosted Apr 25, 2024, 6:02 AM
To customize the highlighted row and column colors in a DataGridView in a .NET application, you can handle the
CellPaintingevent and set the desired colors based on the cell being painted. Here's a sample code snippet to achieve this:By handling the
CellPaintingevent and checking the current cell's row and column indices, you can dynamically set the background color to achieve the desired effect.