I have a popup with a listview inside:
<Popup Name="PopupResultados" Width="200" PlacementTarget="{Binding ElementName=textBoxBuscar}" AllowsTransparency="True" PopupAnimation="Slide">
<ListView Name="listViewResultados" Background="LightGray" BorderThickness="2" SelectionChanged="listViewResultados_SelectionChanged">
<ListView.View>
<GridView x:Name="gridViewResultados" ColumnHeaderContainerStyle="{StaticResource noHeader}">
<GridViewColumn Header="Col1" Width="0" DisplayMemberBinding="{Binding Col1}" />
<GridViewColumn Header="Col2" DisplayMemberBinding="{Binding Col2}" />
</GridView>
</ListView.View>
</ListView>
</Popup>
The listview is filled with a dictionary:
private void buscar(object sender, RoutedEventArgs e)
{
Dictionary<int, String> dicc = admin.buscarEntidad(textBoxBuscar.Text);
if (!PopupResultados.IsOpen)
{
if (dicc.Count() != 0)
foreach (var par in dicc)
listViewResultados.Items.Add(new { Col1 = par.Key, Col2 = par.Value });
else
listViewResultados.Items.Add(new { Col2 = "No hay coincidencias" });
PopupResultados.IsOpen = true;
}
}
Now, I want to select an item in the listview and get the integer value in Col1.
How can I get the integer value?
When I type listViewResultados.SelectedItem. I get only 4 methods: Equals, GetHashCode, GetType and ToString.
Forgot to say that I’m trying to get the integer value inside listViewResultados_SelectionChanged
Hi Cast
listViewResultados.SelectedItemto the Type of Which your Collection Items to wich your ListView ItemsSource is binded. Like if your ItemsSource is binded to List of string then just do it like (string)listViewResultados.SelectedItem. I hope this will help.