Microsoft website
After DataGridView data binding, it is often necessary to convert the data into some format, say 1 for men and 2 for females.
At this point, you need to use the Cellformatting event
Here's an example of Microsoft's official
Private void datagridview1_cellformatting (object sender, Datagridviewcellformattingeventargs e) { // if the column is the Artist column, check the // value. if (This.datagridview1.columns[e.columnindex]. name == "Artist") { if (E . Value != null) { // Check for the string "Pink" in the cell. string stringvalue = (String) e.value; Stringvalue = stringvalue.tolower (); if ((Stringvalue.indexof ("Pink") > -1) { e.CellStyle.BackColor = Color.Pink; } } } else if (This.datagridview1.columns[e.columnindex]. name == "Release date") { shortformdateformat (e); }}
DataGridView cell formatting after data binding