Results 1 to 4 of 4

Thread: [RESOLVED] Keep a user from switching tabs before they click the datagridview

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2014
    Posts
    57

    Resolved [RESOLVED] Keep a user from switching tabs before they click the datagridview

    I have a form with tab controls (TabControl1). There is a datagridview1 above it and when a row is clicked, it populates textboxes in the TabPage1 child. I have a TextBoxID that contains the Primary Key. I would like to validate against that using the validating class to prevent a user from clicking or changing the focus of TabPage1 if TextBoxID.Text=""

    I tried several renditions of something like this...

    Code:
        Private Sub TabControl1_Validating(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles TabControl1.Validating
            If TextBoxID.Text = "" Then
                MsgBox("Field Data Needed For Other Tabs!")
                e.Cancel = True
            End If
        End Sub
    How can I achieve this without having to continue checking other tab enter events for this field being empty?

  2. #2
    Still learning kebo's Avatar
    Join Date
    Apr 2004
    Location
    Gardnerville,nv
    Posts
    3,762

    Re: Keep a user from switching tabs before they click the datagridview

    Maybe look at from the opposite angle. Rather than prevent something if a condition is not true, allow it when a condition is true. The latter may be able to be done by setting the enable bit of the tab control... disable the tab control until the validation succeeds.
    kevin
    Process control doesn't give you good quality, it gives you consistent quality.
    Good quality comes from consistently doing the right things.

    Vague general questions have vague general answers.
    A $100 donation is required for me to help you if you PM me asking for help. Instructions for donating to one of our local charities will be provided.

    ______________________________
    Last edited by kebo : Now. Reason: superfluous typo's

  3. #3
    Member
    Join Date
    Mar 2014
    Posts
    53

    Re: Keep a user from switching tabs before they click the datagridview

    Change the Handle u have there to .click or keep it what works best

    and write a
    Code:
    If PerFormedDataEncode = false Then
    e.cancel
    End If
    Make a new boolean in ur class
    Public PerformedDataEncode As boolean = false

    After ur code that populates the fields
    PerformedDataEncode = true

    Or hide the tabcontrol and show it when the fields are filled

  4. #4

    Thread Starter
    Member
    Join Date
    Dec 2014
    Posts
    57

    Re: Keep a user from switching tabs before they click the datagridview

    Way to think outside the box. That was perfect and looks better too. I set TabControl1.Enabled = False by default load, then on the DataGridView1_CellContentClick I enabled it to True. Just what I needed.

Tags for this Thread

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