Is there a Grid function get object at index ?

Hello,

I can't see a way to just change a specific object in a Grid.

You can add at index or remove at index but i didn't found a way to get object at index or set(replace) an object at index ... is this normal ?

When you have a grid 6x7 and you want to update it is there a better way to just clean it and recreate it ?

Because it make my app really slow to do it like this and i would like to update just some items instead of rebuilding it each time

Tagged:

Answers

  • adamkempadamkemp USInsider, Developer Group Leader mod

    Grids don't work like that. A Grid is just like any other container view, with just a simple list of children. The way that the children are assigned to cells is by using attached properties that are set on the children. Things that may surprise you (and would conflict with your desire to be able to index items by row/column):

    1. Multiple views can occupy the same cell.
    2. A single view can occupy multiple cells.

    Both of those are actually quite common.

    If your layout is static (i.e., always the same number of rows/columns) then you can create wrapper views for each cell and maintain those in your own dictionary or other data structure. Then you can just look up (in your own code) the wrapper view for a given row/column and delete/replace its child.

  • JohnHindJohnHind GBMember ✭✭

    Or you can just iterate through the Children collection until you find the one were the attached properties match the desired row and column:

        public View GetView(int col, int row)
        {
            foreach (View v in Children) if ((col == Grid.GetColumn(v)) && (row == Grid.GetRow(v))) return v;
            return null;
        }
    

    This is implemented as a method of an object inheriting from Grid - otherwise pass the Grid in and use it to qualify "Children" in the above code. Took me a while to work out the unintuitive syntax for accessing the attached properties!

  • snarfsnarf PHMember ✭✭

    @JohnHind How about the cells with multple views inside? thanks

Sign In or Register to comment.