Results 1 to 9 of 9

Thread: VSFlexGrid from VideoSoft - How to validate data?

  1. #1

    Thread Starter
    Addicted Member Michel Jr's Avatar
    Join Date
    Jan 2000
    Location
    Brazil
    Posts
    175

    Question VSFlexGrid from VideoSoft - How to validate data?

    Hi,

    How can I validate the data being added to a VSFlexGrid, before they are commited to my database?
    How event should I use?

    Note: This Grid is made by VideoSoft.

    Thanks in advance,

    Michel Jr.

  2. #2
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    You can validate as the user types by using the ValidateEdit event. This came straight from the Help file...

    Fired before the control exits cell edit mode.

    Syntax
    Private Sub VSFlexGrid_ValidateEdit( ByVal Row As Long, ByVal Col As Long, Cancel As Boolean)

    Remarks
    This event is fired before any changes made by the user are committed to the cell.

    You may trap this event to read the contents of the cell editor with the EditText property and to make sure the entry is valid for the given cell (Row, Col). If the entry fails validation, set the Cancel parameter to True. The changes will be discarded and the control will remain in edit mode.

    If you want to validate keys as they are typed into the editor, use the KeyPressEdit or the ChangeEdit events. For more details on in-cell editing, see the Editable and ComboList properties.

    For example, the code below shows a typical handler for the ValidateEdit event. In this case, column 1 only accepts strings, and column 2 only accepts numbers greater than zero:
    Code:
    Sub fg_ValidateEdit(ByVal Row As Long, ByVal Col As Long, Cancel As Boolean)
            Dim c$
            Select Case Col ' different validation rules for each column
                Case 1 ' column 1 only accepts strings
                    c = Left$(fg.EditText, 1)
                    If UCaseS(c) < "A" And UCase$(c) > "Z" Then Beep: Cancel = True
                Case 2 ' column 2 only accepts numbers > 0
                    If Val(fg.EditText) <= 0 Then Beep: Cancel = True
            End Select
        End Sub

  3. #3

    Thread Starter
    Addicted Member Michel Jr's Avatar
    Join Date
    Jan 2000
    Location
    Brazil
    Posts
    175

    Question

    One more question:

    How can I assing a Field from my table to the VSFlexGrid columns?


    Note: This is the syntax for the standard Microsoft DataGrid:
    DataGrid1.Columns(0).DataField = Adodc1.Recordset.Fields("Name").Name & ""

    What is the syntax for the VSFlexGrid?


    Thanks again...

    Michel Jr.

  4. #4
    Member
    Join Date
    Jul 2015
    Location
    England
    Posts
    42

    Re: VSFlexGrid from VideoSoft - How to validate data?

    Setting Cancel to True in the ValidateEdit event always causes a loud beep on ending the Sub. I never found a way round it.

  5. #5
    Hyperactive Member
    Join Date
    Jan 2018
    Posts
    304

    Re: VSFlexGrid from VideoSoft - How to validate data?

    Quote Originally Posted by LittleTyke View Post
    Setting Cancel to True in the ValidateEdit event always causes a loud beep on ending the Sub. I never found a way round it.
    I've never seen that behavior in FlexGrid. That's why the code above manually adds the beep, since FlexGrid doesn't have it's own noise after Validate. But I never use ValidateEdit, just Validate.

  6. #6
    Member
    Join Date
    Jul 2015
    Location
    England
    Posts
    42

    Re: VSFlexGrid from VideoSoft - How to validate data?

    If you only use Validate, how do you validate an edited cell in the FlexGrid? This is what ValidateEdit is intended for.

  7. #7
    Hyperactive Member
    Join Date
    Jan 2018
    Posts
    304

    Re: VSFlexGrid from VideoSoft - How to validate data?

    I checked a little closer, and the code was actually doing BeforeEdit (save value) AfterEdit (restore old value if a bad value was entered). Probably to get around the doorbell sound in ValidateEdit.

  8. #8
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,676

    Re: VSFlexGrid from VideoSoft - How to validate data?

    I guess the sound is there for people who can't see very well, and/or who are "pro" data-entry types who don't look at the screen while typing (looking instead at the physical document they are copying data from). These people need to know when they've mistyped something without seeing it on the screen.

    Anyone who doesn't like the sound can clear the Critical Stop sound option in Windows Sound settings:

    Name:  2025-02-07_10-20-11.jpg
Views: 53
Size:  35.1 KB

  9. #9
    Member
    Join Date
    Jul 2015
    Location
    England
    Posts
    42

    Re: VSFlexGrid from VideoSoft - How to validate data?

    Actually, in one application I wrote, which also produced this annoying beep, I used the Windows API to disable sound just before the point in the code where the sound originated, and reinstated the previous setting just after. Worked fine, though a really big hammer to crack a nut. It's all very well disabling critical stop, but other programs may indeed justifiably want it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width