Below is my row validating event, I throw the blnNewRow flag in UserAddedRow
(This seems like a hack but I can't find an easier way to do this). This
event fires twice and I can't figure out why? Ideas? If you see anything in
here that seems like bad from please let me know so I can learn the correct
way.
Try
If Usp_Select_1_DataGridView.CanSelect Then
With Usp_Select_1_DataGridView
Dim strError As String = Nothing
.Rows(e.RowIndex).ErrorText = ""
'this fires when a blank row is exited. I fire this
becuase on
'dtagridviewleave I update the changes made to the
dataset.
'if the user presses a button outside of the grid, this
fires and then
'they would need to press the button again.
If Len(Trim(.CurrentRow.Cells(0).FormattedValue)) = 0
And _
Len(Trim(.CurrentRow.Cells(1).FormattedValue)) = 0
And _
Len(Trim(.CurrentRow.Cells(2).FormattedValue)) = 0 Then
MsgBox("New row cancelled, relect an your action if
needed.", _
MsgBoxStyle.OkOnly, "New Row Cancelled, Reselect
Action!")
blnNewRow = False
DsStrategy.RejectChanges()
End If
'This makes sure all 3 fileds are filled int
If Len(Trim(.CurrentRow.Cells(0).FormattedValue)) = 0 Or _
Len(Trim(.CurrentRow.Cells(1).FormattedValue)) = 0 Or _
Len(Trim(.CurrentRow.Cells(2).FormattedValue)) = 0 Then
strError = "You must select a Description, Product
Code and Enter a percentage to continue, " & _
"or press escape to exit the current row"
.Rows(e.RowIndex).ErrorText = strError
e.Cancel = True
Else
'che3ck for pirmary key constraint
Dim intCodeID As Integer = .CurrentRow.Cells(1).Value
Dim drSelect() As DataRow
Dim strFilter As String = "ID1 = " & _
intID1 & " and ID2 = " & inID2 & _
" and ID3 = " & intID3
drSelect = Dsdataset.usp_Select.Select(strFilter)
If blnNewRow Then
If drSelect.Length > 0 Then
strError = "There is already an entry for
this Line/Quarter/Product combo. Please edit the existing data."
.Rows(e.RowIndex).ErrorText = strError
e.Cancel = True
End If
Else
If drSelect.Length > 1 Then
strError = "There is already an entry for
this Line/Quarter/Product combo. Please edit the existing data."
.Rows(e.RowIndex).ErrorText = strError
e.Cancel = True
Exit Try
End If
blnNewRow = False
End If
End If
End With
End If
Catch ex As Exception
MsgBox(ex.Message)
e.Cancel = True
End Try
This is killing me, please let me know I have a deadline on Tuesday and this
is slowing me down too much!!!
thanks,
Greg P
Greg P. - 27 Sep 2006 20:46 GMT
I've continued to work on this and still can't find a reason that when this
sub completes (and it does so sucessfully) it fires again. It even fires a
secondtime before RowValidated fires? This is so weird!!!
Another pieces of info to work with is that when it fires the second time it
thinks the row it just validated (with good data) is empty so it fails the
top test looking for all three fields to be empty. What the heck is going on
here?
Another weird this is if I do a dataset.accept changes it adds a blank row
to the grid? I even to a datagridrefresh and there is a blank row inserted?
When I look at the datatable in the watch window there is not a blank row?
ARRGGGHHH!!!
> Below is my row validating event, I throw the blnNewRow flag in UserAddedRow
> (This seems like a hack but I can't find an easier way to do this). This
[quoted text clipped - 81 lines]
>
> Greg P
Greg P. - 27 Sep 2006 21:03 GMT
I guess I should also state what I am trying to accomplish in this sub.
1) If all 3 cells are empty I want to escape out of the row but fire a
msgbox to let the user know that they only exited the row. (If they pushed a
command buttone that wouldn't fire because they exited the row, so they would
need to press it again)
2) Check ofr a blank cell in any of the 3 fields.
3) if all 3 are filled check the datatable for aprimary key issue, if so
set the error text.
As I said the only way I can seem to do test against whether the row is a
user added row is to through a flag in UserAddedRow. When DataGridView_Leave
fires I call an update function listed below. I know this is a ton of info
but I would rather you have it all up front instead of asking for more later.
If the update function returns true I acceptchanges and do datagrid.refresh
Private Function UpdateSchedule() As Boolean
Dim intAdd As Integer = 0
Dim intEdit As Integer = 0
Dim intDelete As Integer = 0
If DsStrategy.HasChanges Then
Dim AddComposition As dsStrategy.usp_ScheduleSelectDataTable = _
CType(DsStrategy.usp_ScheduleSelect.GetChanges(DataRowState.Added), _
dsStrategy.usp_ScheduleSelectDataTable)
Dim ModComposition As dsStrategy.usp_ScheduleSelectDataTable = _
CType(DsStrategy.usp_ScheduleSelect.GetChanges(DataRowState.Modified), _
dsStrategy.usp_ScheduleSelectDataTable)
Dim DelComposition As dsStrategy.usp_ScheduleSelectDataTable = _
CType(DsStrategy.usp_ScheduleSelect.GetChanges(DataRowState.Deleted), _
dsStrategy.usp_ScheduleSelectDataTable)
Try
'1. Delete Locations Count
If Not DelComposition Is Nothing Then
intDelete += DelComposition.Count
End If
'2. Add Locations Count
If Not AddComposition Is Nothing Then
intAdd += AddComposition.Count
End If
'3. Update Locations Count
If Not ModComposition Is Nothing Then
intEdit += ModComposition.Count
End If
If intAdd > 0 Or intEdit > 0 Or _
intDelete > 0 Then
Dim strMsg As String = "You have: " + vbCrLf + vbCrLf + _
intAdd.ToString + " pending addition(s), " + vbCrLf + _
intEdit.ToString + " pending modification(s) " + vbCrLf
+ _
intDelete.ToString + " pending deletion(s) " + vbCrLf +
vbCrLf + _
"Would you like to save these changes? " + vbCrLf +
vbCrLf + _
"Select Yes to Save or No to continue with out
saving."
If MsgBox(strMsg, MsgBoxStyle.YesNo, _
"Pending Updates Not Saved") = MsgBoxResult.No Then
UpdateSchedule = False
Exit Try ' this skips the add, edit and delete below.
End If
End If
'2. Parent Delete
If Not DelComposition Is Nothing Then
Usp_ScheduleSelectTableAdapter.Update(DelComposition)
UpdateSchedule = True
End If
'3. Parent Add
If Not AddComposition Is Nothing Then
Usp_ScheduleSelectTableAdapter.Update(AddComposition)
UpdateSchedule = True
End If
'4. Parent Update
If Not ModComposition Is Nothing Then
Usp_ScheduleSelectTableAdapter.Update(ModComposition)
UpdateSchedule = True
End If
MsgBox("Your changes have been saved.")
Catch ex As Exception
MsgBox(ex.Message + ex.StackTrace, MsgBoxStyle.Exclamation, _
"Database Updates Failed")
Return False
Finally
If Not DelComposition Is Nothing Then
DelComposition.Dispose()
End If
If Not AddComposition Is Nothing Then
AddComposition.Dispose()
End If
If Not ModComposition Is Nothing Then
ModComposition.Dispose()
End If
End Try
End If
End Function
> Below is my row validating event, I throw the blnNewRow flag in UserAddedRow
> (This seems like a hack but I can't find an easier way to do this). This
[quoted text clipped - 81 lines]
>
> Greg P
Greg P. - 27 Sep 2006 21:55 GMT
I found it but I have no idea why it did what It did. I was setting a couple
of values in the grid in UserAddedRow. When I moved these two commands into
the CellEndEdit (so populated the hidden cells after the user makes some sort
of change) the event stopped firing twice.
This still makes not since to me but... oh well.
> Below is my row validating event, I throw the blnNewRow flag in UserAddedRow
> (This seems like a hack but I can't find an easier way to do this). This
[quoted text clipped - 81 lines]
>
> Greg P