How to save data in listview to sqllite

some1some1 Member ✭✭✭
edited June 25 in Xamarin.Forms
<ContentPage.Resources>

        < ResourceDictionary >

            < local:ByteArrayToImageSourceConverter x:Key="ByteArrayToImage"  />

        </ ResourceDictionary >

    </ ContentPage.Resources >

    < ListView x:Name="iList" RowHeight = "100" HorizontalOptions="Center" ItemSelected="IList_ItemSelected"  >

        <ListView.ItemTemplate >

            <DataTemplate>

                <ViewCell>

                        <StackLayout Orientation="Horizontal" >

                        <Image Source="{Binding PROD_IMAGE, Converter={StaticResource ByteArrayToImage}}" Aspect="AspectFit"  />

                            <Label Text="{Binding PROD_NAME}" TextColor="Black"  VerticalOptions="Center" HorizontalOptions="Center" />

                            <Label x:Name="lblcount"   Text="{Binding Source={x:Reference stepper},Path=Value}" TextColor="Black"  VerticalOptions="Center" HorizontalOptions="EndAndExpand"  />

                        <Stepper x:Name="stepper" Value="{Binding QUANTITY}" Minimum="0" Increment="1"  HorizontalOptions="End" VerticalOptions="Center" />

                    </StackLayout>

                </ViewCell>

            </DataTemplate>

        </ListView.ItemTemplate>

    </ListView>

</ContentPage>

this is my form . I have an image ,label to display product name, then a label to set count based on stepper.

i want save all these data to sqllite in OnDisappearing() . how cani do that ?

Answers

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    I think you have a ObservableCollection that you use to fill the listview (but I don't see it…)

    You can use db.InsertAll (if I remember…)

    https://github.com/praeclarum/sqlite-net/wiki/GettingStarted

    @some1 said:
    <ContentPage.Resources> <ResourceDictionary> <local:ByteArrayToImageSourceConverter x:Key="ByteArrayToImage" /> </ResourceDictionary> </ContentPage.Resources> <ListView x:Name="iList" RowHeight = "100" HorizontalOptions="Center" ItemSelected="IList_ItemSelected" > <ListView.ItemTemplate> <DataTemplate> <ViewCell> <StackLayout Orientation="Horizontal" > <Image Source="{Binding PROD_IMAGE, Converter={StaticResource ByteArrayToImage}}" Aspect="AspectFit" /> <Label Text="{Binding PROD_NAME}" TextColor="Black" VerticalOptions="Center" HorizontalOptions="Center" /> <Label x:Name="lblcount" Text="{Binding Source={x:Reference stepper},Path=Value}" TextColor="Black" VerticalOptions="Center" HorizontalOptions="EndAndExpand" /> <Stepper x:Name="stepper" Value="{Binding QUANTITY}" Minimum="0" Increment="1" HorizontalOptions="End" VerticalOptions="Center" /> </StackLayout> </ViewCell> </DataTemplate> </ListView.ItemTemplate> </ListView> </ContentPage>

    this is my form . I have an image ,label to display product name, then a label to set count based on stepper.

    i want save all these data to sqllite in OnDisappearing() . how cani do that ?

  • some1some1 Member ✭✭✭

    @AlessandroCaliaro iwill not get that count from ObservableCollection because it's value is changed according to stepper .

  • LucasZhangLucasZhang Member, Xamarin Team Xamurai

    Set the binding mode as TwoWay

    Value="{Binding QUANTITY,Mode=TwoWay}"
    

    And you can get the value in ViewModel

Sign In or Register to comment.