Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Everyone,

I need to implement autosuggest feature in a DataGridTextColumn. How can I achieve this?

I am looking for solution with as little project dependency as possible

What I have tried:

I have tried a couple approaches but everything seems to have its own problem. This is my closest attempt to implement the feature, however, this approach does not allow me to input text or any kind into the textbox within the DataGridTemplateColumn

HTML
<pre>                
<DataGridTemplateColumn Header="Product Number" Width="120">
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Grid>
                                <TextBlock x:Name="ProductNumberBox" Text="{Binding ProductNumber, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" />
                                <Popup Width="{Binding Path=ActualWidth, ElementName=ProductNumberBox}" StaysOpen="False" PlacementTarget="{Binding ElementName=ProductNumberBox}" Placement="Bottom" IsOpen="{Binding DataContext.GridPopupIsOpen, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}">
                                    <ListBox ItemsSource="{Binding DataContext.Parts, UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" SelectedItem="{Binding DataContext.SelectedSuggestedPartInGrid, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged, RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Window}}}">
                                        <ListBox.ItemTemplate>
                                            <DataTemplate>
                                                    <TextBlock Text="{Binding ProductNumber}"/>
                                            </DataTemplate>
                                        </ListBox.ItemTemplate>
                                    </ListBox>
                                </Popup>
                            </Grid>
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
Posted
Updated 23-Dec-20 6:00am
v2

1 solution

You need to explain the "use case"; i.e. what are we supposed to "see". Your concept of "auto suggest" could be anything. A "tooltip" is a "suggestion"; and is baked in.

wpf - How do I Add a Tooltip To a DataGridTextColumn - Stack Overflow[^]
 
Share this answer
 
Comments
Lyandor 23-Dec-20 20:33pm    
I am actually open to any suggestions, thus the vague question. My problem lies in using the feature in DataGridColumn. The items in the suggestion list will have to reference DataContext.SomeListProperty but SelectedItem will have to reference someproperty of an object within a list which is bound to the DataGrid itself.

Basically I am trying to implement a list of suggestions which when selected, either by binding selected item or pressing enter when an item from the suggestion box is selected, will set the string inside of the TextBox in the DataGridColumn to the SelectedItem's Value

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900