Forum Xamarin.Forms

To show dynamic collection of data inside listView's ViewCell

RaviKanasagraRaviKanasagra INMember ✭✭

I want to show collection of items in each ViewCell of List view.

I found one line which I have found it useful but not fully helpful.

It says to use grid as itemtemplate for listview's viewcell but it did not explain, how would I count number of child element for each viewcell.

 'var myDataTemplate = new DataTemplate(() =>
            var cell = new ViewCell();
            var grid = new Grid();

            foreach (var record in myRecords)
                grid.RowDefinitions.Add(new RowDefinition());

            foreach (var field in myFields)
                grid.ColumnDefinitions.Add(new ColumnDefinition());

             * Populate grid here...

            cell.View = grid;
            return cell;

Other logic I was thinking was to use list inside list but it is not working.


  • RaviKanasagraRaviKanasagra INMember ✭✭

    I know how many columns I have but I do have to identify for each viewcell how many rows would required. How do I do it?

    Also, I have to add textbox in columns and want to connect to viewmodel for collecting data.

  • MaharshiChoudhuryMaharshiChoudhury INMember ✭✭✭

    well you have a viewcell
    viewcell.view will give you the grid and then you can count how many children you have.

  • RaviKanasagraRaviKanasagra INMember ✭✭

    that count I need to set that we received from viewcell.view

    Kindly let me know how would I set it? and How would I data bind from viewModel to each cell in grid?

Sign In or Register to comment.