This might be a stupid question but i haven't been able to find an answer anywhere.
I am trying to make it possible when a user clicks on a certain row in the datagrid the entire row will be selected.
In WPF i just have to set the selection mode to FullRowSelect but in my current project the datagrid doesnt have this option. The only 2 options i have now are SelectionMode : Single or Extended.
Currently my XAML code looks like this :
<sdk:DataGrid x:Name="ShowKlant" Grid.Column="0" AutoGenerateColumns="False" CanUserReorderColumns="False" IsReadOnly="True" SelectionChanged="ShowKlant_SelectionChanged" AlternatingRowBackground="#FF4568C7" RowBackground="#AA73A4D4">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Header="Klant ID" Binding="{Binding KlantID}"/>
<sdk:DataGridTextColumn Header="Voornaam" Binding="{Binding Voornaam}"/>
<sdk:DataGridTextColumn Header="Achternaam" Binding="{Binding Achternaam}"/>
</sdk:DataGrid.Columns>
</sdk:DataGrid>
The reason i want to do this is that when the entire row is selected i can hopefully use code similar to this to get the value from the first cell.
idklant = Convert.ToInt32(ShowKlant.SelectedRows[0].Cells[0].Value);
Found the solution thanks to this question, after using my error report in a search.
link to solution: How to read the value in the first cell in a selected row of a Datagrid?
您是否尝试设置数据网格的选择模式?
<DataGrid x:Name="test" SelectionMode="Single" >
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.