i am working with datagridview in win forms now i have to change the color of cell when any user click on that cell i have to change that cell color to red for which i have use this code
DataGridViewCellStyle CellStyle = new DataGridViewCellStyle();
CellStyle.BackColor = Color.Red;
dataGridView2.Rows[e.RowIndex].Cells[e.ColumnIndex].Style = CellStyle;
but now if user has selected any other cell in same row then its color should be change to
red and previous selected should make white again as non selected.
You need to maintain a reference to the previously selected cell so you can change it back.