Reputation: 147
I've a simple listview with a gridview and I'm trying to get values of certain column.
My XAML
<ListView SelectionMode="Single" Margin="10,10,0,0" x:Name="activos" Height="211" VerticalAlignment="Top" HorizontalAlignment="Left" Width="555" SizeChanged="activos_SizeChanged" SelectionChanged="activos_SelectionChanged" IsSynchronizedWithCurrentItem="True">
<ListView.Resources>
<ResourceDictionary>
<Style x:Key="hiddenStyle" TargetType="GridViewColumnHeader">
<Setter Property="Visibility" Value="Collapsed"/>
</Style>
<Style TargetType="{x:Type CheckBox}" x:Key="DataGridCheckBox">
<Setter Property="HorizontalAlignment" Value="Center" /> <Setter Property="HorizontalContentAlignment" Value="Center" /> <Setter Property="IsEnabled" Value="False" /> <Setter Property="Margin" Value="11 3" /> <Setter Property="VerticalAlignment" Value="Center" /> <Setter Property="VerticalContentAlignment" Value="Center" /> <Setter Property="Width" Value="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type GridViewColumn}},Path=ActualWidth}" />
</Style>
</ResourceDictionary>
</ListView.Resources>
<ListView.View>
<GridView x:Name="act_">
<GridViewColumn Header="Code" Width="0" DisplayMemberBinding="{Binding coddiag}" HeaderContainerStyle="{StaticResource hiddenStyle}" />
<GridViewColumn Header="Diagnóstico" Width="400" DisplayMemberBinding="{Binding diag}" />
<GridViewColumn Header="Princip." Width="50">
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox Style="{StaticResource DataGridCheckBox}" IsChecked="{Binding princi}" Focusable="False" IsHitTestVisible="False" Name="Complete" IsThreeState="False" BorderBrush="Black" Foreground="Black"></CheckBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="Fecha" Width="{x:Static System:Double.NaN}" DisplayMemberBinding="{Binding fecha, StringFormat='dd/MM/yyyy'}" />
</GridView>
</ListView.View>
</ListView>
Basically what I'm trying to do is access to GridViewColumn Code value whenever I change the selected row and store its value.
I thought it would be something easier like Grid[Row,Column] or something like that... but after some researching it looks like I will need to make use of other methods...
Upvotes: 1
Views: 506
Reputation: 2046
You can add ListView.SelectedItem binding on a property of your view model. Your view model will be tracking selecting changes from that point. So when seleted item is changed you get new value in this property. Therefore you can access any property (column value) of selected item in your view model's code.
Upvotes: 1