Tabcontrol

O

ORC

Hi,

I've used a tabcontrol containing several different kind of Usercontrols.
When the user has finished entering data in a control (that still has focus)
a usual thing to do is to select another tab. However - if the selected
control validates to false (e.g. if the user has entered non valid data like
a letter in a number field) the tabcontrol should stay on the current tab
with the Usercontrol still focused so that the user can change it. How to do
that???????
I have tried to use the 'SelectedIndexChanged' event, but it is useless
because the event fires AFTER the tab has been drawn but BEfORE the controls
on the new page has been drawn - strange behaviour! I can't find a way
through this so any help or inspiration is highly appreciated.

Thanks,
Ole
 
O

ORC

Hi Daniel,

The implementation showed there is almost what I have tried to do and also,
as him, without any luck - so help is still needed.

Thanks
Ole
 
D

Daniel Moth

Given that the approach has been working for me, all I can say is post a
small complete sample that does not work for you and we can spot the
difference.

Cheers
Daniel
 
O

ORC

I think the problem is that this:

private void tabControl1_SelectedIndexChanged(object sender,
System.EventArgs e)
{
if( tabControl1.SelectedIndex == 0)
{
textBox1.Focus();
textBox1.SelectAll();
}
}

Doesn't work. The textBox got the focus in a very short moment, but the
tabcontrol removes it immediately again :-( - any suggestion on how to
prevent that?

Thanks,
Ole
 
O

ORC

Thanks. The codesnippet I showed has to do with my original question because
it consist of two task:
1) Preventing the tabpage to change - easily solved by using the
selectIndexChanged Event.
2) Setting focus back to the control that hasn't validated to a valid
value - Can maybe be solved - I will try to use the tabcontrols focusevent
and let you know the result.

Thank you for your help Daniel - it is highly appreciated!
Ole
 
O

ORC

OK - found a solution. In all my userControls I have placed property caled
willValidateTofalse in which the entered value will be checked without
further action e.g. with some "try-catch"'s. If a control returns with a
true the tabControl is shifted back to it's previous page where the control
is located - thereby raising the LostFocus event in the control. The
LostFocus event forces focus back to the control that needs validation.

Ole
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top