user7615935
user7615935

Reputation:

Passing data From ListView Item to next Form

I know how to send data from an Entry, Label to the next Form , but how can i do this with a ListView. I want a simple direct approach.

My XAML code :

<ListView x:Name="MyClientslistView" HasUnevenRows="true"  ItemTapped="OnSalesReport">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell>

                            <StackLayout Orientation="Vertical" VerticalOptions="Center"  Margin="5" >
                                <Label Text="{Binding client_name}" TextColor="#A7A392" />
                                <Label Text="{Binding client_address}" TextColor="Black" />
                                <Label Text="{Binding client_phone}"  TextColor="Black" />
                                <Label Text="{Binding client_email}"  TextColor="Black" />
                                <Label Text="{Binding AssignStatus}"  TextColor="Black" />
                                <Label Text="{Binding assignmentComments}"  TextColor="Black" />
                            </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

I already have loaded data from JSON to the ListView , now currently i want to move each ID on he Item to the Next Form , how can i tackle that ?

Upvotes: 0

Views: 720

Answers (2)

Alex Chengalan
Alex Chengalan

Reputation: 8281

You can get the item from ItemTapped listener. In your case use below solution.

void OnSalesReport(object sender, Xamarin.Forms.ItemTappedEventArgs e)
    {
        YourItemModel item = (YourItemModel)((ListView)sender).SelectedItem;
        ((ListView)sender).SelectedItem = null;
        Navigation.PushAsync(new NextPage(item));
    }

Upvotes: 1

Diego Rafael Souza
Diego Rafael Souza

Reputation: 5314

Sorry for the poor english

You can have your entire item at your event handler private void OnSalesReport(object sender, ItemTappedEventArgs e) through e.Item. You must do var item = ((YourTypeClassItem)e.Item); then you get things like item.client_name and probably item.client_id.

I hope it helps you.

Upvotes: 1

Related Questions