Visual Basic .Net

with VB.Net: When using a DataViewGird,and entering text into a column and then tabbing or clicking another column and if the data entered is not what it should be, how do I give a message, and keep focus on that column.
slay21455Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
You can use the CellValidating event of the grid, and if the validation fails, set e.Cancel = true to stay in that cell
0
slay21455Author Commented:
Thank you for your answer, however

Sorry, but the answer does not give me enough detail.  I am not that familiar with Vb.Net and would like a more detailed example of the events and the code.

Jack
0
Éric MoreauSenior .Net ConsultantCommented:
here is a sample:

Option Strict On

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
        DataGridView1.DataSource = GetSomeData()
    End Sub

    Private Sub DataGridView1_CellValidating(sender As Object, e As DataGridViewCellValidatingEventArgs) Handles DataGridView1.CellValidating
        If e.ColumnIndex = 1 Then
            If e.FormattedValue.ToString() <> "Valid" Then
                e.Cancel = True
            End If
        End If
    End Sub

    Private Function GetSomeData() As DataTable
        Dim dt As New DataTable("Test")
        With dt
            .Columns.Add("ID", GetType(Integer))
            .Columns.Add("Description", GetType(String))

            .Rows.Add(New Object() {1, "Valid"})
            .Rows.Add(New Object() {2, "Valid"})
            .Rows.Add(New Object() {3, "Valid"})
            .Rows.Add(New Object() {4, "Valid"})
            .Rows.Add(New Object() {5, "Valid"})
        End With
        Return dt
    End Function

End Clas

Open in new window

s
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

slay21455Author Commented:
Thank you very much Eric, I appreciate the answer and the quit response.
0
Éric MoreauSenior .Net ConsultantCommented:
you need to accept the comment if it fulfills your requirement to close the question
0
Éric MoreauSenior .Net ConsultantCommented:
Got good comments on that proposed solution
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.