[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?
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
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
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.