i am working with uwp i need to get the value the selecteditem from list and get the details of the employee
the details of the employee is store in
List<EmployeeItem> Employeelist = DataAccess.getallemployee(empdetails);
i need to get the detail of a selected employee from the list
<ListView x:Name="EmployeeListView" Width="auto" Grid.Row="4" IsItemClickEnabled="True" ItemClick="EmployeeListView_ItemClick">
<ListView.ItemTemplate>
<DataTemplate x:DataType="local:EmployeeItem">
<TextBlock x:Name="firstname" Grid.Column="0"
Text="{Binding FirstName}"
FontSize="17" />
my click fucntion is
private void EmployeeListView_ItemClick(object sender, ItemClickEventArgs e)
{
Frame.Navigate(typeof(seleted));
}
CodePudding user response:
you can use Click event
:
private void listView1_Click(object sender, EventArgs e)
{
var firstSelectedItem = listView1.SelectedItems[0].Text;
}
CodePudding user response:
Based on your code, you are using single selection mode in your ListView. It is suggested to handle the SelectionChanged Event
to get the selected item and do what you want in the next.
You could check more information here: ListView Guide.
Xaml:
<ListView x:Name="EmployeeListView" Width="auto" Grid.Row="4" SelectionChanged="EmployeeListView_SelectionChanged">
<ListView.ItemTemplate>
<DataTemplate x:DataType="local:EmployeeItem">
<TextBlock x:Name="firstname" Grid.Column="0" Text="{Binding FirstName}" FontSize="17" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Code-behind:
private void EmployeeListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
EmployeeItem item = EmployeeListView.SelectedItem as EmployeeItem;
//do what you want
Frame.Navigate(typeof(seleted));
}