【问题标题】:Selecting a full row in DataGrid, Silverlight Navigation Application在 DataGrid、Silverlight 导航应用程序中选择整行
【发布时间】:2016-12-31 23:51:36
【问题描述】:

这可能是一个愚蠢的问题,但我无法在任何地方找到答案。

我试图使当用户单击数据网格中的某一行时,将选择整行。

在 WPF 中,我只需将选择模式设置为 FullRowSelect,但在我当前的项目中,数据网格没有此选项。我现在仅有的 2 个选项是 SelectionMode:Single 或 Extended。

目前我的 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);

在搜索中使用我的错误报告后,由于这个问题找到了解决方案。

解决方案链接: How to read the value in the first cell in a selected row of a Datagrid?

【问题讨论】:

    标签: c# xaml datagrid


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-02-15
      • 1970-01-01
      • 2013-06-02
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多