How to validate dataGridViewFields

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AnuRane1988
    New Member
    • Feb 2008
    • 1

    How to validate dataGridViewFields

    I am doing my Project in VB.net 2005
    I hav one DataGridView on Form
    Two of it's column represent the Date
    so I want to validate that user hav enter valid date into Grid

    Or der is any direact method to hav dtagridview column in DateFormat.
  • misza
    New Member
    • Feb 2008
    • 13

    #2
    Originally posted by AnuRane1988
    I am doing my Project in VB.net 2005
    I hav one DataGridView on Form
    Two of it's column represent the Date
    so I want to validate that user hav enter valid date into Grid

    Or der is any direact method to hav dtagridview column in DateFormat.
    You can do it in CellValueChange d event;

    As a parameter you'll get DataGridViewCel lEventArgs which has ColumnIndex and RowIndex properties
    - this will point you to the cell changed;

    then you can call your validating function and, if needed, reassign/reset the value of that cell (DataGridViewCe ll.Value)

    I'm sure there are other ways to do this, but it worked for me

    afaik, there's no Date format to be specified for a DataGridView

    Michal

    Comment

    • misza
      New Member
      • Feb 2008
      • 13

      #3
      Originally posted by misza
      afaik, there's no Date format to be specified for a DataGridView
      unfortunately or rather fortunately;) I was wrong about this one:
      there's no datacolumn type as such, but you can specify content type to whatever is valid for you, e.g.:
      Code:
      DataGridViewColumn column;
      column = new DataGridViewTextBoxColumn(); // here you specify what does each cell look and behave like, check documentation for other "looks"
      column.Name = "colName";
      column.HeaderText = "header text";
      column.ValueType = Type.GetType("System.DateTime"); // this is the Date type; you can use (probably) whatever type you want, just remember to put full path to the type
      dataGridView1.Columns.Add(column); // add the column to your grid
      hope this helps

      Michal

      Comment

      Working...