4

i want to create a checkbox in listview using xaml, after selecting the multiple checkbox click button to get all selected value.My code is :

<ContentPage.Content>
    <ListView  x:Name="ProductsListView">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <ViewCell.View>
                        <StackLayout Spacing="0">
                            <Label Text="{Binding retail_modified_item_id}" 
                               TextColor="Blue" FontSize="13" />
                            <Label Text="{Binding name, StringFormat='Name : 
                               {0:N}'}" TextColor="black" FontSize="10"  />
                            <Label Text="{Binding retail_price, 
                               StringFormat='Price : {0:N}'}" 
                               TextColor="black" FontSize="10" />
                        </StackLayout>
                    </ViewCell.View>
                </ViewCell>                            
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</ContentPage.Content>

my output is; output without checkbox

i tried some sample code from https://www.ignatiuz.com/blog/xamarin/button-check-box-with-list-item-in-xamarin-forms-listview/

but i'm getting input:checkbox not found

i am new to xamarin please give some sample code or link to do this

0

4 Answers 4

2

You can use Plugin.InputKit from Nuget.

Usage

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:xxx"
             xmlns:input="clr-namespace:Plugin.InputKit.Shared.Controls;assembly=Plugin.InputKit"
             x:Class="xxx.MainPage">


<ContentPage.Content>
 <ListView  x:Name="ProductsListView">
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <ViewCell.View>
                    <StackLayout Spacing="0">
                        <Label Text="{Binding retail_modified_item_id}" 
                           TextColor="Blue" FontSize="13" />
                        <Label Text="{Binding name, StringFormat='Name : 
                           {0:N}'}" TextColor="black" FontSize="10"  />
                        <Label Text="{Binding retail_price, 
                           StringFormat='Price : {0:N}'}" 
                           TextColor="black" FontSize="10" />
                        <input:CheckBox Text="xxx" Type="Check"/>  
                    </StackLayout>
                </ViewCell.View>
            </ViewCell>                            
        </DataTemplate>
    </ListView.ItemTemplate>
 </ListView>
</ContentPage.Content>        

</ContentPage>
Sign up to request clarification or add additional context in comments.

1 Comment

@AnuPriya can you provide the sample?
1

I have written a content on implementing the multiselect listview in xamarin forms. Please check this : https://androidwithashray.blogspot.com/2018/03/multiselect-list-view-using-xamarin.html

Hope this helps.

Comments

1

Add/remove value to local collection using OnCheckChanged method. I used this way:

<ListView>
    <ListView.ItemTemplate>
        <DataTemplate>
            <ViewCell>
                <StackLayout Orientation="Horizontal">
                    <Label Text="Some item" />
                    <CheckBox 
                        IsChecked="true" 
                        CheckedChanged="OnCheckedChanged" 
                        HorizontalOptions="EndAndExpand"/>
                </StackLayout>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

1 Comment

I am not a big fan of nuGet unless there is no other choice. I know this is debatable and perhaps I am wrong in this, but whatever. Thank you for this answer
0

If you need to have checkboxes inside a listview, you can use Xamarin.Forms.InputKi (https://github.com/enisn/Xamarin.Forms.InputKit)

Then I would define it like this inside a DataTemplate's ViewCell:

 <input:CheckBox Text="Hello World I'm Option 2" Type="Check"/>

There are also Bindable properties and events which you can use depending on your scenario:

CheckChanged: (Event) Invokes when check changed.

CheckChangedCommand: (Command) Bindable Command, executed when check changed.

Key: (int) A key you can set to define checkboxes as ID.

Text: (string) Text to display description

IsChecked: (bool) Checkbox checked situation. Works TwoWay Binding as default.

Color: (Color) Color of selected check.

TextColor: (Color) Color of description text.

Type: (CheckType) Type of checkbox checked style. (Check,Cross,Star,Box etc.)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.