the database I'm connecting my app for the "percent" column is using values less than 1 (i.e 15% is stored as 0,15 in the database), so I'm using the Format = ".00%" to display the values in the DataGrid column.
Question is How to properly let users insert the values bigger than 1 - to write i.e. 50 or 50% in the cell - and transform it to 0,5 in the database.
I was looking for DataGridViewCellValidatingEventHandler and added the Event levDGV_PercentCellValidating, but I don't know how to change the values...
private void levDGV_PercentCellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
string dataPropertyName = levDGV.Columns[e.ColumnIndex].DataPropertyName; // deliveryProcent
// Abort validation if cell is not in the "deliveryProcent" column.
if (!dataPropertyName.Equals("deliveryProcent")) return;
levDGV.Rows[e.RowIndex].ErrorText = "";
string testValue = e.FormattedValue.ToString();
char lastChar = testValue[testValue.Length - 1];
if (lastChar == (char)37)
{
//TODO: Remove % character from entered string
}
//TODO: divide the value by 100 and set as currentCell value
}
how to transform entered value to the properly validated one (divided by 100)?