Control data entry in DataGridView RRS feed

  • Question

  • I would like to do the following:
    1. Prohibit direct data entry in a date field, and allow data entry only calendar
    2. Check the values ​​entered in a numeric field, and replace the system error message to my message.
    Can you please tell how to do it. I tried to do under paragraph 2 as follows:
        private void dgv1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
          if (e.ColumnIndex == 3 && dgv1.CurrentCell.Value.ToString() != "")
            int num;
            Boolean bl = int.TryParse(dgv1.CurrentCell.Value.ToString(), out num);
            if (bl == false)
              MessageBox.Show("Input does not correspond to the number format!", "ADO.NET Study", MessageBoxButtons.OK);
    but it turns out nonsense, if I enter in a numeric field numbers - then everything works fine, but if I enter text, the system message.
    If e.ColumnIndex == 3 && dgv1.CurrentCell.Value.ToString ()! = "" replace e.ColumnIndex == 3, then at the first click on my message box appears an error, because the value of the cell is empty. Project to link


    • Edited by tumanovalex Saturday, May 11, 2013 11:53 AM
    Saturday, May 11, 2013 11:53 AM


All replies