Вопрос

I'm still a beginner with regards to C# and WPF, and I am unable to find an answer to my question.

I have a WPF datagrid this is displayed in a readonly mode and would like to be able to have the user use Ctrl-F to find a cell value in the datagrid. Is this or some variant of possible, or do I need to create a search box as a control and take things from there?

Any suggestions would be greatly appreciated.

(Scathing comments are also welcome!)

I am currently using 2010 Express. The datagrid is defined below.

<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" />
Это было полезно?

Решение

I do not know a build in search but maybe this'll help you: DataGrid search

A nice approach to build a textsearch (including highlighting).

//edit

You can use InputBindings and e.g. open a search window from your viewmodel.

    <DataGrid.InputBindings>
        <KeyBinding Key="L" Modifiers="Control" Command="{Binding SearchCommand}"/>
    </DataGrid.InputBindings>
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top