Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to protect the DataGridView cell value can't nul?l
Message
From
19/05/2011 04:15:45
 
 
To
All
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
How to protect the DataGridView cell value can't nul?l
Environment versions
Environment:
VB 9.0
OS:
Windows XP
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01511095
Message ID:
01511095
Views:
88
Hi all,
i use vb.net , DataGridView, dataset ( aid primary key, aname not null )...... if i want the user press add or save button can check two fields
must not null value . i already try to wirte a function but must the dataset fields aname set allow null, database can set not null. If i set aname not
allow null, my function can not run before already dispaly error ( the dataset aname can not null)
And if the user entry the current row aid, aname null , after click the top row also error
How can i do, thank you .
Private Sub StorerBindingNavigatorSaveItem_Click(ByVal sender As System.Object, _
     ByVal e As System.EventArgs) Handles CompanyBindingNavigatorSaveItem.Click
        save()
    End Sub

 Private Sub save()
        If Not UsergradeDataGridView.Rows(UsergradeDataGridView.Rows.Count - 1).Cells(0).Value Is DBNull.Value And Not UsergradeDataGridView.Rows(UsergradeDataGridView.Rows.Count - 1).Cells(1).Value Is DBNull.Value Then
            Try
                Me.Validate()
                Me.UsergradeBindingSource.EndEdit()

                Me.TableAdapterManager.UpdateAll(Me.WilsonDataSet)
            Catch ex As Exception
                MsgBox(ex.Message, MsgBoxStyle.SystemModal, "Data error!")
            Finally

            End Try
        Else

        End If
end sub


Private Sub UsergradeDataGridView_CellValidating(ByVal sender As Object, _
            ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) _
            Handles UsergradeDataGridView.CellValidating

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

        Try
            With UsergradeDataGridView
                If e.ColumnIndex = 0 Then
                    If CStr(e.FormattedValue).Length = 0 Then
                        strErrMsg = "Grade ID must not empty!"
                        .Rows(e.RowIndex).ErrorText = strErrMsg
                        e.Cancel = True
                        MsgBox("Grade ID must not empty!", 48, "Warning")
                    ElseIf CStr(e.FormattedValue).Length > 5 Then
                        strErrMsg = "Grade ID length must not over 5 char" 
                        .Rows(e.RowIndex).ErrorText = strErrMsg
                        e.Cancel = True
  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(5), _
                                    5)
                                htTable.Add(sProductID, iRow)
                            Next
                        Catch ex As Exception
                            strErrMsg = "Grade ID must not duplicate!"
                            .Rows(e.RowIndex).ErrorText = strErrMsg
                            e.Cancel = True
                            MsgBox("Grade ID must not duplicate!", 48, "Warning")
                        End Try
                    End If
                End If

                If e.ColumnIndex = 1 Then

                    If CStr(e.FormattedValue).Length > 50 Then
                        strErrMsg = "Grade Desc. length must not over 50 char!"
                        .Rows(e.RowIndex).ErrorText = strErrMsg
                        e.Cancel = True
                        MsgBox("Grade Desc. must not over 50 char!", 48, "Warning")

                    End If
                End If
            End With

        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Information, "User Grade entry error!")
        End Try

    End Sub
Reply
Map
View

Click here to load this message in the networking platform