Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How can i control the datagridview data in 2 feild not same?
Message
From
09/11/2011 23:54:16
 
 
To
All
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
How can i control the datagridview data in 2 feild not same?
Environment versions
Environment:
VB 9.0
OS:
Windows XP
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01528543
Message ID:
01528543
Views:
64
Hi all,
I use vb.net and datagridview. I want to control 2 feild when user input the datagridview data is duplicate, then will pop message.
For example, table A (a,b) . a b
----- -----
1 2
3 4

When user entry 1 value in a field is ok , but entry 1 value in a field and 2 value in b field in same time ,then pop message.
But i only know can check 1 field. Anyone know how can i do? Thank you.
Private Sub dg_CellValidating(ByVal sender As Object, _
            ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles dg.CellValidating


        Dim strErrMsg As String
        For i = 0 To dg.Rows.Count - 1
            dg.Rows(i).ErrorText = ""
        Next

        Try
            With dg
                If e.ColumnIndex = 0 Then
                    If CStr(e.FormattedValue).Length = 0 Then
                        strErrMsg = "a must entry!"
                        .Rows(e.RowIndex).ErrorText = strErrMsg
                        e.Cancel = True
                        MsgBox("a must entry!", 48, "warning")
                    Else
                        Dim htTable As Hashtable = New Hashtable
                        Dim iRow As Integer
                        Dim sProductID As String
                        Try
                            .Rows(iRow).ErrorText = ""

                            For iRow = 0 To .Rows.Count - 1               
                                sProductID = _
                                    Microsoft.VisualBasic.Left( _
                                    CStr(.Rows(iRow).Cells(0). _
                                    EditedFormattedValue) & Space(4), _
                                    4)
                                htTable.Add(sProductID, iRow)
                            Next
                        Catch ex As Exception
                            strErrMsg = "a must not duplicate."
                            .Rows(e.RowIndex).ErrorText = strErrMsg
                            e.Cancel = True
                            MsgBox("a must not duplicate!", 48, "warning")
                        End Try
                    End If
                End If
end sub
Next
Reply
Map
View

Click here to load this message in the networking platform