How to Check for a Zero Entry in a DG?

  • Thread starter Thread starter Mr. B
  • Start date Start date
M

Mr. B

I have a master DataSet... I then select (filter) some items and display them
on a 2nd DataGrid for editing (only the 6th column gets any editing).

The following code works fine. BUT what it does not do is check for a Zero
(not a Null) value. I know I can do a search for the 7 rows (maximum) in
column #6 for a Zero and reject the entry (and give a message box)? But I
think it would be under the 'not best coding' flag.

I know I could do an IF THEN kind of check for each column #6 in each row.
But IS there a simpler way?

My current code (for accepting a Row Deletion and Edit of Column #6) is as
follows:


If DsEditData.HasChanges Then
Try
Dim exDataModified, exDataDeleted As Integer

' Edit Hours
exDataDeleted = daEditData.Update(DsEditData.tblTimeEntry)

' Delete Row
exDataModified += daEditData.Update(DsEditData.tblTimeEntry.Select("",
"", DataViewRowState.Deleted))

Catch ex As Exception
MessageBox.Show(ex.Message, "Update failed!", MessageBoxButtons.OK,
MessageBoxIcon.Error)

End Try
Else
MessageBox.Show("No Changes Made!", "SubmitChanges",
MessageBoxButtons.OK, MessageBoxIcon.Information)

Exit Sub
End If


Any tips appreciated.

Regards,

Bruce
 
What database are you using? Most allow some form or another of field
validation. You can catch this when the user attempts to insert a zero into
the database. I'm not sure but a bound datagrid may even catch this prior
to issuing the update...

--
============
Frank Hickman
NobleSoft, Inc.
============
Replace the _nosp@m_ with @ to reply.
 
Frank Hickman said:
What database are you using? Most allow some form or another of field
validation. You can catch this when the user attempts to insert a zero into
the database. I'm not sure but a bound datagrid may even catch this prior

Damn... I keep forgetting to add that kind of info....

VB.net
MS Access

dumping it into a DataGrid.

Bruce
 
If you open your database in Access and select the field you don't want to
contain zeros you will see a field property called Validation Rule...just
enter <> 0 in that and enter whatever error message you want in the
Validation Text field. When the datagrid attempts to save a record that
does not meet the validation rule, the validation message will pop up as a
message box. You can also override this message box by putting code in
DataGrid1_Error function like this...

Private Sub DataGrid1_Error(ByVal DataError As Integer, Response As Integer)
If DataError = 6153 Then ' Validation error???
MsgBox "Field value cannot be zero.", vbCritical, "Data Entry Error"
Response = 0
End If
End Sub

But you may just want to let the datagrid display the default message.

HTH
--
============
Frank Hickman
NobleSoft, Inc.
============
Replace the _nosp@m_ with @ to reply.
 
Frank Hickman said:
DataGrid1_Error function like this...
But you may just want to let the datagrid display the default message.

Thanks Frank!

BTW... know of a way to TEST for a case when a ListView column width has
changed? In other words IF a user changes a column width, I'd like to know so
I can reset it. Locking the columns is not required because sometimes the
info is buried, and stretching the column allows them to view it.

I just want to reset the column widths to my default values IF a change was
made.

Thanks!

Bruce
 
Select the control id in ClassWizard and override the HDN_ENDTRACK
notification message...

HTH
--
============
Frank Hickman
NobleSoft, Inc.
============
Replace the _nosp@m_ with @ to reply.
 
Frank Hickman said:
Select the control id in ClassWizard and override the HDN_ENDTRACK
notification message...

Hmmm... I can't find the ClassWizard (only have the DataFormWizard... and that
doesn't run). Maybe it's because I have the vanila flavour Standard VB.net?

Oh well...

Regards,

Bruce
 
DOH! Didn't realize you where using VB.net ClassWizard is for VC++
anyway, there should be a callback function for the control on your form.
I'm still waiting on my .NET stuff so I can't really help you how to do it
but it should be there.

--
============
Frank Hickman
NobleSoft, Inc.
============
Replace the _nosp@m_ with @ to reply.
 
Frank Hickman said:
DOH! Didn't realize you where using VB.net ClassWizard is for VC++
anyway, there should be a callback function for the control on your form.

LOL... Oh well... serves me right for forgetting to say Vb.net (do that all
the time). Keep forgetting people here use VB and C#, etc.

But thanks anyways!

I think your Validation Rule in the DB is probably the way to go.

Regards,

Bruce
 
Back
Top