Forum Xamarin Xamarin.Forms

how to get grid children value which is at specfic place ??

I am using grid view to show my labels text and i want to get value of grid children which is at 4th position or else but its giving only as label. I want to get that label's value. Please help ?? can anyone suggest me ??

Best Answer

Answers

  • JohnHardmanJohnHardman GBUniversity admin
    edited September 2016

    @KaranveerSingh - What do you mean by a Label's value?

    To work with the Children of an existing Grid object, you can iterate through the Children (the Children property is of type IGridList< View >, then use Grid.GetColumn(), Grid.GetRow(), Grid.GetColumnSpan() or Grid.GetRowSpan() as required to find the position of each child in the Grid.

    If by a Label's value, you mean the Text property of the Label, you simply get the View retrieved by enumerating, cast it to Label (if that's what it is), and then get the Text property.

    string value = ((Label) view).Text;

  • KaranveerSinghKaranveerSingh USMember ✭✭

    See I have one grid view in which i have some items but i want to get value of grid children which is at 4th position.
    Like,
    var count = selectedItemGridView.Children.ElementAt(4); DisplayAlert("Alert","fdgf "+count, "Ok");

    This code shows there is Label but when i want to get value by text Property
    Like,

    var count = selectedItemGridView.Children.ElementAt(4).Text; DisplayAlert("Alert","fdgf "+count, "Ok");

    Then error comes no text property like this

  • KaranveerSinghKaranveerSingh USMember ✭✭

    Thanks a lot, It is working. :) Really thanks :)

Sign In or Register to comment.