Blue Theme Orange Theme Green Theme Red Theme
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Home | Forums | ASP.NET 2.0 Tutorials | Web Services | How Do I...? | Class Browser | WPF Quick Starts | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
Search :       Advanced Search »
Home » Blogs Home » Blog Detail

Validate and focus DataGridView Cell

 by Ankur Gupta on Jul 20, 2010

Validate and focus DataGridView Cell
Comments: 0 Views: 4629 Printable Version 

Validate and focus DataGridView Cell

We can use a lot of validations on DatagridView Cell.

Most of the people have some problem to focus the grid view Cell after some validation message

Ex. If any user put any string value in currency column then it show some validation message like “Enter Currency only” but after that the focus moves in another cell.

So we should use CellValidating event of DataGridView.

You can easily understand to see the following examples.

    Private Sub grdBilling_CellValidating(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles grdBilling.CellValidating

 

                If Not grdBilling.Rows(e.RowIndex).Cells(4).Value Is Nothing Then

                    If Not IsNumeric(grdBilling.Rows(e.RowIndex).Cells(4).Value) Then

                        MessageBox.Show("Enter Numeric value only", "", MessageBoxButtons.OK, MessageBoxIcon.Error)

                        e.Cancel = True

                    Else

        End If

    End Sub

 

Here e.Cancel = True return the focus in the Validated cell

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
 
What do you say about this post? Post a comment here
*Title:
*Comment:
 
Comments not available.
Nevron Gauge for SharePoint
Become a Sponsor

 Blogger's Profile
Age: 29
Location:
Title: Project Manager
Joined: May 15, 2010
Education: Masters Degree
 More Blogs from this Blogger
No record available
 Latest Blogs
[Video] OnClose Handler
[Video] Storing and Loading the Window and Toolbar position
The Euclidean Algorithm
Swapping Exe Process
How Exe file is Generated by VS2005 C++ Project?
What is Exe
Header files: Multiple Inclusion problem - Solution B
Header files: Multiple Inclusion problem - Solution A
Header files: Multiple Inclusion problem - Reason
Header files: Multiple Inclusion problem
View all »
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 
Team Foundation Server Hosting
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.