1

I have a datagrid (having all columns as DataGridTextColumn) showing data of a child table. Now there are some columns which are bringing a Foreign Key value from Parent Table.

<UserControl x:Class="DMS.Presentation.CustomerWorkSpaceView"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:local="clr-namespace:DMS.Presentation"
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300">
<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="Auto" />
    </Grid.ColumnDefinitions>                
                <DataGrid Name="datagridCustomers" AutoGenerateColumns="False" Loaded="datagridCustomers_Loaded" IsReadOnly="True">
                    <DataGrid.Columns>
                        <DataGridTextColumn Header="ID" Binding="{Binding Path=ID}"></DataGridTextColumn>
                        <DataGridTextColumn Header="Name" Binding="{Binding Path=Name}"></DataGridTextColumn>
                        <DataGridTextColumn Header="Contact No" Binding="{Binding Path=ContactNo}"></DataGridTextColumn>
                        <DataGridTextColumn Header="Company ID" Binding="{Binding Path=CompanyID}"></DataGridTextColumn>                       
                    </DataGrid.Columns>
                </DataGrid>
            </HeaderedContentControl>
        </ScrollViewer>
    </HeaderedContentControl>
</Grid>

What I want to Do

If user edits the cell of a Foreign Key column (say Company ID), it should start suggesting it the possible values (just like Twitter starts suggesting the names using AJAX the moment we type @ or # - refer to screenshot).

Twitter Suggestions

By Possible Values I mean

Simply the rows of COMPANY table. I want to get the result of this query as possible values:

SELECT * FROM COMPANY
WHERE ID LIKE '%@IDEnteredValue%' 

(where IDEnteredValue means value entered in cell of ID in our grid)

I ONLY need its Front-end Implementation

Failed Scientist
  • 1,977
  • 3
  • 29
  • 48
  • So you are saying you already have the result of the query working, you just don't know how to make the text box use those values like an auto complete filter? – Zack Mar 13 '15 at 14:59
  • Yes Zack. Exactly! I want those values to be hovered there just like they do in Twitter, etc as I have shown in modified answer – Failed Scientist Mar 13 '15 at 15:01
  • Only thing I can find is the WPF Toolkit which includes an AutoCompleteBox, http://wpf.codeplex.com/releases/view/40535 and the article introducing it http://www.jeff.wilcox.name/2008/10/introducing-autocompletebox/ from this answer http://stackoverflow.com/a/2338707/1804496 The article is talking about Silverlight, so maybe that is not the right one anyway.. – Zack Mar 13 '15 at 15:02
  • Can't we make a custom control and show there as "ToolTip/Suggestions"? – Failed Scientist Mar 13 '15 at 15:07
  • There is this https://wpfautocomplete.codeplex.com/ WPF AutoComplete project that was updated on March 10th that looks promising. – Zack Mar 13 '15 at 16:34
  • Thanks. But does it work for dataGrid as well? – Failed Scientist Mar 13 '15 at 16:37
  • 1
    I don't think you can just replace the DataGridTextColumn with the AutoCompleteTextBox straight up, but you could use a DataGridTemplateColumn and put an AutoCompleteTextBox in the DataGridTemplateColumn.CellTemplate like is shown here http://www.wpf-tutorial.com/datagrid-control/custom-columns/ – Zack Mar 13 '15 at 16:46

0 Answers0