|
-
May 17th, 2007, 02:30 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] [2005] Validate Datagridview data
I have a column in a DGV that contains directories. When the user enters a directory, I want to validate the directory before I allow the user to continue. Currently, I'm trying to use the CellLeave event to handle this and everything works if I modify an exsiting row. If I enter an invalid directory in a new row and choose to not accept the change, I get an index out of range error.
I know that the problem is with the canceledit butI can't think of another way to do this. Any ideas?
vb Code:
Private Sub dgvFiles_CellLeave(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvFiles.CellLeave
Dim strDir As String
Dim strWarn As String
Dim strTitle As String
If dgvFiles.Rows(e.RowIndex).IsNewRow Then Return
strDir = CStr(dgvFiles.Rows(e.RowIndex).Cells("dir").EditedFormattedValue)
strWarn = strDir & " is not a valid directory." & vbCrLf & _
"Do you want to retain this directory Value?"
strTitle = "Invalid Directory"
If Not Directory.Exists(strDir) Then
If MessageBox.Show(strWarn, strTitle, MessageBoxButtons.YesNo, _
MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) _
= Windows.Forms.DialogResult.No Then
dgvFiles.CancelEdit()
End If
End If
End Sub
-
May 17th, 2007, 02:40 PM
#2
Thread Starter
Hyperactive Member
Re: [2005] Validate Datagridview data
It never fails. Once I post a thread, I discover the answer.
I moved my code to the CellValidating event and everything works.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|