简体   繁体   English

在DataGrid,Silverlight导航应用程序中选择整行

[英]Selecting a full row in DataGrid, Silverlight Navigation Application

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. 在WPF中,我只需要将选择模式设置为FullRowSelect,但是在我当前的项目中,datagrid没有此选项。 The only 2 options i have now are SelectionMode : Single or Extended. 我现在仅有的两个选项是SelectionMode:Single或Extended。

Currently my XAML code looks like this : 目前,我的XAML代码如下所示:

<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所选行中第一个单元格中的值?

您是否尝试设置数据网格的选择模式?

<DataGrid x:Name="test" SelectionMode="Single" >

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM