Click here to Skip to main content
15,896,527 members
Home / Discussions / C#
   

C#

 
GeneralImplementation in C# Pin
Diego12326-May-05 0:52
Diego12326-May-05 0:52 
GeneralRe: Implementation in C# Pin
Marc Clifton26-May-05 1:04
mvaMarc Clifton26-May-05 1:04 
GeneralRe: Implementation in C# Pin
Colin Angus Mackay26-May-05 1:49
Colin Angus Mackay26-May-05 1:49 
GeneralRe: Implementation in C# Pin
S. Senthil Kumar26-May-05 2:55
S. Senthil Kumar26-May-05 2:55 
GeneralRe: Implementation in C# Pin
Colin Angus Mackay26-May-05 3:16
Colin Angus Mackay26-May-05 3:16 
GeneralRe: Implementation in C# Pin
S. Senthil Kumar26-May-05 4:24
S. Senthil Kumar26-May-05 4:24 
GeneralWhy toolbar buttons doesn't care of CausesValidation Pin
Itanium26-May-05 0:38
Itanium26-May-05 0:38 
GeneralRe: Why toolbar buttons doesn't care of CausesValidation Pin
Luis Alonso Ramos26-May-05 5:12
Luis Alonso Ramos26-May-05 5:12 
I ran into this problem sometime ago. I have several MDI children, each with a toolbar. So I added this routine to the base class, and call it as the first thing on th ButtonClick handler for the toolbar.
/// <summary>
/// Causes the validation events for the current focused control, without
/// it losing it.
/// </summary>
/// <remarks>Walks recursively through all the form's controls to find
/// the one that currently has the focus.</remarks>
protected void ValidateFocusedControl()
{
    foreach(Control ctl in Controls)
        if(ValidateFocusedControlRecursive(ctl))
            break;
}

/// <summary>
/// Helper function for ValidateFocusedControl.  Walks recursively the
/// children of the Control passed as a parameter.
/// </summary>
/// <param name="ctl">Control to walk its children.</param>
/// <returns>True if the focused control was found, false to keep
/// searching</returns>
/// <remarks>If the focused control is found, a new text box is created,
/// the focus set to it, and then back to focused control.</remarks>
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;
    }

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

    return false;
}
It basically finds which is the focused control, creates a new TextBox, gives it focus, and sets focus back to the original control.

Good luck!

-- LuisR



Luis Alonso Ramos
Intelectix - Chihuahua, Mexico

Not much here: My CP Blog!

GeneralRe: Why toolbar buttons doesn't care of CausesValidation Pin
Luis Alonso Ramos26-May-05 5:13
Luis Alonso Ramos26-May-05 5:13 
GeneralRe: Why toolbar buttons doesn't care of CausesValidation Pin
Itanium31-May-05 22:42
Itanium31-May-05 22:42 
GeneralRe: Why toolbar buttons doesn't care of CausesValidation Pin
Luis Alonso Ramos1-Jun-05 6:01
Luis Alonso Ramos1-Jun-05 6:01 
Generaldatagrid complex object binding Pin
nonick226-May-05 0:09
nonick226-May-05 0:09 
GeneralDisplay line and column on satusbar Pin
hoangsamac25-May-05 23:45
hoangsamac25-May-05 23:45 
Generalgetting the ListBox list as an array Pin
Green Fuze25-May-05 23:41
Green Fuze25-May-05 23:41 
GeneralRe: getting the ListBox list as an array Pin
pubududilena26-May-05 0:07
pubududilena26-May-05 0:07 
GeneralRe: getting the ListBox list as an array Pin
Green Fuze26-May-05 1:26
Green Fuze26-May-05 1:26 
GeneralNew starter - Common Module Q. Pin
Member 199247025-May-05 23:11
Member 199247025-May-05 23:11 
GeneralRe: New starter - Common Module Q. Pin
Itanium26-May-05 0:10
Itanium26-May-05 0:10 
GeneralRe: New starter - Common Module Q. Pin
Member 199247026-May-05 1:03
Member 199247026-May-05 1:03 
Generalget Time on Server Pin
SEAGames2225-May-05 23:00
SEAGames2225-May-05 23:00 
GeneralRe: get Time on Server Pin
pubududilena25-May-05 23:52
pubududilena25-May-05 23:52 
GeneralRe: get Time on Server Pin
Dave Kreskowiak26-May-05 4:02
mveDave Kreskowiak26-May-05 4:02 
QuestionModule like vb.net ? Pin
LIUCKAS25-May-05 22:42
LIUCKAS25-May-05 22:42 
AnswerRe: Module like vb.net ? Pin
Colin Angus Mackay25-May-05 22:52
Colin Angus Mackay25-May-05 22:52 
GeneralRe: Module like vb.net ? Pin
LIUCKAS25-May-05 23:14
LIUCKAS25-May-05 23:14 

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.