Click here to Skip to main content
16,016,623 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi guys,
I've got a TabControl with 2 TabPages. On each TabPage I've got some TextBoxes and ComboBoxes. On the Form there is as well a "Next" Button (onLoad Enabled=false) which should be activated when all TextBoxes/ComboBoxes are filled.
To loop through all the TextBoxes/ComboBoxes on the TabPages I'll solve using:

TabControl.TabPageCollection pages = tabControl.TabPages;
foreach (TabPage page in pages)
{
page.Refresh();
var firstEmptyTextBox = (from t in page.Controls.OfType<TextBox>()
where String.IsNullOrEmpty(t.Text)
select t).FirstOrDefault();

var firstEmptyComboBox = (from t in page.Controls.OfType<ComboBox>()
where String.IsNullOrEmpty(t.Text)
select t).FirstOrDefault();
btnNext.Enabled =
(firstEmptyTextBox == null && firstEmptyComboBox == null);
}

but which Event on TabControl/TabPage should I check when changing the TextBox/ComboBox Input? I tried "Enter, Click" etc. without success..
Thanks for your help
Posted

1 solution

You could setup a custom event on the tab pages that's fired to indicate its "ready" status based on the state of the desired controls. The "ready"/"not ready" state can be put into a custom EventArgs object.

When both tabpages have fired the event with the appropriate ready/not ready status, you can then take the appropriate action.
 
Share this answer
 
v2
Comments
andywawa 13-Jul-11 4:20am    
Hi John,
thanks for your answer. To write a custom Event is one thing, but what fires the Event actually? Let's say I've got 15 TextBoxes on each TabPage. You surely don't mean, that I should implement my Event on every TextBox TextChanged-Event?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900