【问题标题】:WPF DataGrid - "Ctrl-F" type FunctionalityWPF DataGrid - “Ctrl-F”类型的功能
【发布时间】:2014-04-24 09:27:15
【问题描述】:

我还是 C# 和 WPF 的初学者,我无法找到我的问题的答案。

我有一个 WPF 数据网格,它以只读模式显示,并希望能够让用户使用 Ctrl-F 在数据网格中查找单元格值。这是可能的还是某种变体,还是我需要创建一个搜索框作为控件并从那里获取内容?

任何建议将不胜感激。

(也欢迎尖刻的cmets!)

我目前使用的是 2010 Express。数据网格定义如下。

<DataGrid Name="DataGrid1"   Background="LightGray" RowBackground="LightYellow" 
              BorderBrush="Gray" BorderThickness="5" AlternatingRowBackground="LightBlue" HorizontalScrollBarVisibility="Visible"
              VerticalScrollBarVisibility="Visible" AutoGenerateColumns="True" Margin="0.1,0.1,0.1,0.1" HorizontalAlignment="Left" 
              CanUserReorderColumns="True" CanUserResizeColumns="True" CanUserResizeRows="False" CanUserSortColumns="True" 
              SelectionMode="Extended" SelectionUnit="FullRow" IsReadOnly="True"
              Width="1395" />

【问题讨论】:

  • 我现在正在构建同样的东西,你最后的方法是什么?

标签: c# wpf wpfdatagrid


【解决方案1】:

我不知道内置搜索,但也许这会对你有所帮助:DataGrid search

构建文本搜索的好方法(包括突出显示)。

//编辑

您可以使用 InputBindings 和例如从您的视图模型中打开一个搜索窗口。

    <DataGrid.InputBindings>
        <KeyBinding Key="L" Modifiers="Control" Command="{Binding SearchCommand}"/>
    </DataGrid.InputBindings>

【讨论】:

  • 虽然我的意图是找到一种使用“Cntl-F”或类似名称的方法,但您的链接确实为使用文本搜索框提供了一个很好的介绍。如果没有其他建议,我可能会走那条路。谢谢你的建议。
  • 好的,我编辑了我的答案。也许 InputBindings 会帮助你。我不太确定它们是否适用于只读 DataGrid。
  • Nergal - 实际上我今天有机会点击您在第一篇文章中提供的链接并浏览建议的代码。它解决了我大约 95% 的问题,所以我将继续并将其标记为已关闭。另外,我必须学习一些新的东西,不要太寒酸。再次感谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-08-25
  • 2022-12-02
  • 2013-05-27
  • 1970-01-01
  • 2011-01-04
  • 1970-01-01
  • 2016-05-21
相关资源
最近更新 更多