locked
How to access the gridview inside a usercontrol?

    Question

  • Hi,

         I have a usercontrol in which am placing a gridview.

    Now am importing that usercontrol in Mainpage.xaml. There is also a button in my Mainpage.xaml. On clicking this button, I want to set the selected index of the gridview which is inside my user control. Naturally the click code lies in Mainpage.xaml.cs. But am unable to access the gridview from Mainpage.xaml.cs as its inaccessible due to its protection level.

    Kindly suggest me a way to achieve this. I need to change the selectedIndex of the gridview upon each button click.

    Any help is really appreciated as am in great need of it

    Thanks

    Rajesh

    Thursday, June 19, 2014 9:11 AM

Answers

  • set beside the x:Name of the gridview also x:FieldModifier="public" and also make sure the user control has a xname (but based on your error i think you already have that)


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Thursday, June 19, 2014 10:13 AM

All replies

  • set beside the x:Name of the gridview also x:FieldModifier="public" and also make sure the user control has a xname (but based on your error i think you already have that)


    Microsoft Certified Solutions Developer - Windows Store Apps Using C#

    Thursday, June 19, 2014 10:13 AM
  • Thanks a lot Dave. I got it with your solution.

    Point to mention, I also got a similar solution where using the x:name of the user control, I used "FindName" method and could access the gridview inside that user control by passing the GridView's x:name as the parameter to "FindName" menthod.

    With your solution, I can directly access the gridview without the necessity of "FindName".

    It was a good learning.!! Thanks again.

    Thursday, June 19, 2014 11:59 AM
  • Do you use any toolkit so this can work? It doesn't work in my Windows 8.1 store app. I still can't access the gridview's name from the MainPage. Any help?
    Tuesday, April 7, 2015 9:58 AM