How to validate the Data Grid view
  • how to validate the data grid view if the cell value is nullorempty or nullorwhitespace it the cell value should be 0 as same as my data grid view only accept the numeric value
  • 1 Comment sorted by
  • Hi select Datagridview and then go to CellValidating Event and put below code its just accept number.


    decimal varDecimal;

    // we will not check the very new row is not any point in validating its initial value.
    if (DataGridView1.Rows[e.RowIndex].IsNewRow) { return true; }
    if (!decimal.TryParse(e.FormattedValue.ToString(),
    out varDecimal) || varDecimal < 0)
    {
    e.Cancel = true;
    MessageBox.Show("Kindly insert numeric value", "www.codingresolved.com", MessageBoxButtons.OK, MessageBoxIcon.Information);
    return false;
    }
    else
    {
    return true;
    }
    - See more at: http://codingresolved.com/discussion/147/datagridview-cell-numeric-only-c/p1

Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook

Popular Posts of the Week

Optimum Creative