Reputation: 745
Following this guide: https://youtu.be/vNOEp_23Pa0?t=334
The guy has the following line:
Search.txt.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
Now every time I do it I get a red line only under the AutoCompleteMode next to Search.txt.
With error saying :
CS1061 'TextBox' does not contain a definition for 'AutoCompleteMode' and no
extension method 'AutoCompleteMode' accepting a first argument of type 'TextBox' could be
found (are you missing a using directive or an assembly reference?).
Now I've searched everywhere online with no luck. So is it possible to have autocomplete/database connectivity in C# ?
This is my first application so huge beginner. Thanks very much.
Upvotes: 1
Views: 1115
Reputation: 15794
Not directly. There's a bunch of third party controls (including WPF Toolkit) which implement an autocomplete textbox.
A non-third party approach that many use involve taking the ComboBox
and using it's autocomplete feature. You can override the style so that it looks and feels like a textbox, so this is a quick-and-dirty way to do it.
The other approach (which I feel is the more orthodox way) is to add an adorner containing the autocomplete functionality, to the textbox. It's a bit more work, but you can really style it to your heart's content. I've used this approach, because I often need to present an autocomplete dropdown as the user types, then tokenize the input, and present the autocomplete again as the user keeps on typing. Kind of like how JIRA does it. This sort of functionality is too advanced for a simple combobox. You'll probably find that most of the third party controls follow the adorner pattern, or something similar to that approach.
Upvotes: 2
Reputation: 432
The WPF textbox System.Windows.Controls.Textbox
does not have AutoCompleteMode. I didn't check the video, but I suspect that they are using the WinForms textbox System.Windows.Forms.Textbox
, which does.
Upvotes: 0