Click here to Skip to main content
16,011,608 members
Home / Discussions / C#
   

C#

 
GeneralRe: No validation events when clicking on a toolbar Pin
Luis Alonso Ramos16-Oct-04 15:49
Luis Alonso Ramos16-Oct-04 15:49 
GeneralRe: No validation events when clicking on a toolbar Pin
Heath Stewart16-Oct-04 20:58
protectorHeath Stewart16-Oct-04 20:58 
GeneralRe: No validation events when clicking on a toolbar Pin
Luis Alonso Ramos16-Oct-04 22:07
Luis Alonso Ramos16-Oct-04 22:07 
GeneralRe: No validation events when clicking on a toolbar Pin
Luis Alonso Ramos18-Oct-04 14:02
Luis Alonso Ramos18-Oct-04 14:02 
GeneralRe: No validation events when clicking on a toolbar Pin
Heath Stewart18-Oct-04 14:04
protectorHeath Stewart18-Oct-04 14:04 
GeneralRe: No validation events when clicking on a toolbar Pin
Luis Alonso Ramos18-Oct-04 14:23
Luis Alonso Ramos18-Oct-04 14:23 
GeneralRe: No validation events when clicking on a toolbar Pin
Heath Stewart18-Oct-04 16:08
protectorHeath Stewart18-Oct-04 16:08 
GeneralRe: No validation events when clicking on a toolbar Pin
Luis Alonso Ramos19-Oct-04 6:03
Luis Alonso Ramos19-Oct-04 6:03 
Hello Heath,

Finally fixed it. This is what I did:
public void ValidateFocusedControl()
{
    foreach(Control ctl in Controls)
        if(ValidateFocusedControlRecursive(ctl))
            break;
}

bool ValidateFocusedControlRecursive(Control ctl)
{
    if(ctl.Focused)
    {
        if(ctl.CausesValidation)
        {
            // Make current focused control lose focus, and then get
            // it back, so we can force its validation
            TextBox txtBox = new TextBox();
            txtBox.Bounds = new Rectangle(-100, -100, 1, 1);
            txtBox.Parent = ctl.Parent;
            txtBox.Focus();
            ctl.Focus();
            txtBox.Parent = null;
            txtBox.Dispose();
        }
        return true;
    }

    foreach(Control ctl2 in ctl.Controls)
        if(ValidateFocusedControlRecursive(ctl2))
            return true;

    return false;
}
Basically, just create a control, set focus to it, and then set the focus back to my control. It works!

Thanks for all your help!

-- LuisR



Luis Alonso Ramos
Intelectix - Chihuahua, Mexico

Not much here: My CP Blog!

GeneralRe: No validation events when clicking on a toolbar Pin
Heath Stewart19-Oct-04 7:14
protectorHeath Stewart19-Oct-04 7:14 
GeneralRe: No validation events when clicking on a toolbar Pin
Luis Alonso Ramos19-Oct-04 7:39
Luis Alonso Ramos19-Oct-04 7:39 
GeneralGetting active MdiChild Pin
Luis Alonso Ramos16-Oct-04 12:29
Luis Alonso Ramos16-Oct-04 12:29 
GeneralRe: Getting active MdiChild Pin
Alex Korchemniy16-Oct-04 14:45
Alex Korchemniy16-Oct-04 14:45 
GeneralRe: Getting active MdiChild Pin
Luis Alonso Ramos16-Oct-04 15:17
Luis Alonso Ramos16-Oct-04 15:17 
Generalsearch mechanism Pin
mathon16-Oct-04 9:56
mathon16-Oct-04 9:56 
GeneralRe: search mechanism Pin
Alex Korchemniy16-Oct-04 11:15
Alex Korchemniy16-Oct-04 11:15 
GeneralRe: search mechanism Pin
mathon16-Oct-04 13:06
mathon16-Oct-04 13:06 
GeneralRe: search mechanism Pin
Alex Korchemniy16-Oct-04 14:36
Alex Korchemniy16-Oct-04 14:36 
GeneralRe: search mechanism Pin
mathon16-Oct-04 22:22
mathon16-Oct-04 22:22 
GeneralRe: search mechanism Pin
mathon16-Oct-04 22:29
mathon16-Oct-04 22:29 
General[Message Deleted] Pin
Bedevian16-Oct-04 7:54
Bedevian16-Oct-04 7:54 
GeneralRe: Find String in txt file Pin
Alex Korchemniy16-Oct-04 8:56
Alex Korchemniy16-Oct-04 8:56 
GeneralConsole-Like Text Output Control Or.... Pin
osirisgothra16-Oct-04 7:34
osirisgothra16-Oct-04 7:34 
GeneralRe: Console-Like Text Output Control Or.... Pin
Alex Korchemniy16-Oct-04 8:50
Alex Korchemniy16-Oct-04 8:50 
GeneralRe: Console-Like Text Output Control Or.... Pin
Alex Korchemniy16-Oct-04 8:52
Alex Korchemniy16-Oct-04 8:52 
GeneralGDI+ - line chart Pin
xiaowenjie16-Oct-04 4:56
xiaowenjie16-Oct-04 4:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.