Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Only Allow to enter Numeric values Datagridview specific column

Is there any way to customize datagridview column to accept only numeric values. Also if user press any other character other than numbers nothing must type on the current cell.Is there any way to solve this problem

like image 738
user2431035 Avatar asked Dec 05 '22 10:12

user2431035


1 Answers

    private void gvAppSummary_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
    {
        if (gvAppSummary.CurrentCell.ColumnIndex == intRate)
        {
            e.Control.KeyPress += new KeyPressEventHandler(gvAppSummary_KeyPress);
        }
    }

    private void gvAppSummary_KeyPress(object sender, KeyPressEventArgs e)
    {
        if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) && e.KeyChar != '.')
        {
            e.Handled = true;
        }
    }
like image 82
RekhaShanmugam Avatar answered Dec 29 '22 00:12

RekhaShanmugam