locked
WPF Control Collection RRS feed

  • Question

  • Hi guys,

    I want to traverse through the collections of controls placed inside the grid or any type of control container can any expert help me out in this? plz.......

    Friday, April 29, 2011 4:38 AM

Answers

  • Hi,

    Download the UI Helper Class from the following path.

    http://www.hardcodet.net/uploads/2009/06/UIHelper.cs

    //get all TextBox controls within the grid:
    Grid container;
    IEnumerable<TextBox> editors = container.FindChildren<TextBox>();

    //get all the controls within the grid:
    Grid container;
    IEnumerable<Control> editors = container.FindChildren<Control>();

     

    Now you can loop editors and traverse each control.


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This will help other members to find the solution easily.
    Friday, April 29, 2011 5:26 AM
  • Hi Zeeshan Ansari,

    I think ksvimal has provide a good way, have you tried it?

     

    Best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Zeeshan Ansari Saturday, December 17, 2011 7:38 AM
    Monday, May 2, 2011 5:03 AM

All replies

  • Hi,

    Download the UI Helper Class from the following path.

    http://www.hardcodet.net/uploads/2009/06/UIHelper.cs

    //get all TextBox controls within the grid:
    Grid container;
    IEnumerable<TextBox> editors = container.FindChildren<TextBox>();

    //get all the controls within the grid:
    Grid container;
    IEnumerable<Control> editors = container.FindChildren<Control>();

     

    Now you can loop editors and traverse each control.


    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This will help other members to find the solution easily.
    Friday, April 29, 2011 5:26 AM
  • Hi Zeeshan Ansari,

    I think ksvimal has provide a good way, have you tried it?

     

    Best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Zeeshan Ansari Saturday, December 17, 2011 7:38 AM
    Monday, May 2, 2011 5:03 AM
  • Thanks a lot ksvimal !
    Zishan Ansari .Net Developer
    Saturday, December 10, 2011 3:53 AM
  • I'd like to use this but it doesn't work. Is there a non-3rd party way to do this in version 2008?

    Error    1    The type or namespace name 'TextBox' could not be found (are you missing a using directive or an assembly reference?)    D:\VisualStudioProjects\WPF2008\wpfBadChar\Window1.xaml.cs    30    25    wpfBadChar

    Error    2    The name 'container' does not exist in the current context    D:\VisualStudioProjects\WPF2008\wpfBadChar\Window1.xaml.cs    30    44    wpfBadChar

    Error    3    The type or namespace name 'TextBox' could not be found (are you missing a using directive or an assembly reference?)    D:\VisualStudioProjects\WPF2008\wpfBadChar\Window1.xaml.cs    30    67    wpfBadChar

    Tuesday, March 6, 2012 11:43 PM