.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> Windows Application >> Post New QuestionBookmark and Share Subscribe to Forum

Problem in DataGridView Cell Validation in c#

Posted By: Naim Khan     Posted Date: January 01, 2010    Points:2   Category :Windows Application
Hello every one,

I have One Data GridView. i want to Make Validation on Cell . Cell is Accept only Numaric and Decimal Values and is should not be Greater than of 100 if its Greater Than 100 than give me MSG... i donthave any idea of this Validation if u know than please let me know as soon as possible...

Thanks In Advance

Responses
Author: Faizal             
Posted Date: January 02, 2010     Points: 5   

Hi Naim,

yes you can validate datagridview cell like this

private void dataGridView1_CellValidating(object sender,
DataGridViewCellValidatingEventArgs e)
{
// Validate the CompanyName entry by disallowing empty strings.
if (dataGridView1.Columns[e.ColumnIndex].Name == "CompanyName")
{
if (e.FormattedValue == null &&
String.IsNullOrEmpty(e.FormattedValue.ToString()))
{
dataGridView1.Rows[e.RowIndex].ErrorText =
"Company Name must not be empty";
e.Cancel = true;
}
}
}

void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
{
// Clear the row error in case the user presses ESC.
dataGridView1.Rows[e.RowIndex].ErrorText = String.Empty;
}


you can modify the above code depend upon your requirement

http://msdn.microsoft.com/en-us/library/ykdxa0bc.aspx

Author: Naim Khan             
Posted Date: January 05, 2010     Points: 5   

thanks for the reply but i don't want that sir. i just want only double values and it should not be grater
than 100. thats it i want... so if you have any idea than let me know

thanks in Advance

Naim Khan


Software Developer
khan.naim786@yahoo.com
khan.naeem1987@gmail.com


Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend