Hi.
I want enter only number and date to datagridview.
for example (12,15 & 12/03/2009).. if i can enter any string it show error message . how can go further any one help me.
thanks in advance
gopal
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Niradhip ChakrabortyPosted Apr 20, 2009, 10:42 AM
You can handle the CellParsing event to parse the cell value to a correct format, something like this
void dataGridView1_CellParsing(object sender, DataGridViewCellParsingEventArgs e)
{
if (e.ColumnIndex == 0)
{
string date = (string)e.Value;
try
{
string month = date.Substring(0, 2);
string day = date.Substring(2, 2);
string year = date.Substring(4, 4);
e.Value = new DateTime(
Convert.ToInt32(year),
Convert.ToInt32(month),
Convert.ToInt32(day));
e.ParsingApplied = true;
}
catch(Exception ex)
{
MessageBox.Show("parsing error!");
}
}
}
anushaPosted Apr 20, 2009, 8:59 AM
Hi Gopal,
I think u can write validation code in the 'CellEndEdit' event of the datagridview.
In this event u will get the e.rowindex.
Thanks
anusha.