0
votes

I want to create a list view with four column, first two column will have text and next two column will have clickable button(image). Number of rows is not fixed- so data binding is require. Should support android and iOS. please suggest which xamarin control will be best suited for me.

Can i use data template as shown in https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/templates/data-templates/selector/

or should use Grid, Grid layout or any other.

======== Solution Applied=============

<ListView x:Name="listViewExpenses" CachingStrategy="RecycleElement" VerticalOptions="FillAndExpand" RowHeight="40">
<ListView.ItemTemplate>
    <DataTemplate>
        <ViewCell>
            <Grid >
                <Grid.ColumnDefinitions>

                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="40"/>
                </Grid.ColumnDefinitions>
                <!--<Label x:Name="idLabel" Text="{Binding Id}"/>-->
                <Label x:Name="textLabel1" Grid.Column="0" Text="{Binding Text}"/>
                <!--<Button x:Name="btnEdit" Image="icon.png" HeightRequest="50" WidthRequest="50"  Grid.Column="2" CommandParameter="{Binding Id}"  Clicked="OnEditClicked" />-->
                <StackLayout Grid.Column="1">
                    <Image Source="EditRed.png" VerticalOptions="Center" >
                        <Image.GestureRecognizers>
                            <TapGestureRecognizer
    Tapped="OnEditTapped" 
        CommandParameter="{Binding Id}"/>
                        </Image.GestureRecognizers>
                    </Image>
                </StackLayout>
            </Grid>
        </ViewCell>
    </DataTemplate>
</ListView.ItemTemplate>
</ListView>`enter code here`

===================================== Thanks,

@paul

2
I assume you mean "iOS", not "ISO", which is the International Standards Organization.Jason
if you want a databound grid control, you'll need to use a 3rd party control. There are several free and commercial ones availableJason

2 Answers

1
votes

As the number of rows is not fixed but each row will look the same, I would suggest a List View with an inline data template.

https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/templates/data-templates/creating/

0
votes

Data templates you mentioned is required in case of different row views. For your case Grid should be sufficient. You can add rows dynamically for example like shown here

https://forums.xamarin.com/discussion/42393/need-to-add-rows-dynamically-in-a-grid

If that doesn't work you can use ListView with custom cells

https://developer.xamarin.com/guides/xamarin-forms/user-interface/listview/customizing-cell-appearance/