Click here to Skip to main content
15,907,395 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want Validation in DataGridview Cell for which i want to enter only below value of 100 in that cell....(cell is for like inputing Percentage)
i dont want to enter greater than 100
so...how to do that
Posted

1 solution

Hello,

One way to do it is to use the CellValidating event.

See here: http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellvalidating.aspx[^]

you could do it like that:

C#
private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
{
    if (e.ColumnIndex == _indexOfColumnTocheck)
    {
        int value;
        if (int.TryParse((string)e.FormattedValue, out value))
        {
            if (value > 100) { e.Cancel = true; }
        }
        else
        {
            e.Cancel = true;
        }
    }
}





Valery.
 
Share this answer
 
Comments
jayeshhh 12-Sep-13 9:23am    
Thank You

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900