开发者

Autocomplete email address and/or names in C#

开发者 https://www.devze.com 2022-12-08 05:43 出处:网络
I\'m looking for a solution like the one discussed here, b开发者_如何学Gout for C# WinForms. Link here

I'm looking for a solution like the one discussed here, b开发者_如何学Gout for C# WinForms. Link here

To rephrase, is it possible to do textbox autocompletes in C# using a single data source with multiple lines? Result should be like Gmail's TO: field in creating emails, or similarly MS Outlook's TO: field.

For example, the data set might be:

"John Williams" (john.williams@gmail.com)

"Bob Johnson" (john.jacobs@gmail.com)

"Willy Johnston" (willy.williams@gmail.com)

"Willy Williams" (johnjohn@gmail.com)

... and I should be able to type "john" and all four would be suggested. If I typed "johns" then the second and third entries would be suggested.

This is more advanced than the auto-complete provided by .NET by default.

Thanks, -Greg


The WinForms 2.0 controls already provide this functionality in the AutoCompleteSource property. You can set this to a datasource or build your own list of strings with AutoCompleteStringCollection.


I ended up writing my own UserControl custom class to take care of this. It didn't appear there was anything out there that met my needs.

I've provided the source and DLL here under BSD: http://code.google.com/p/email-autocomplete

Basically, it emulates the functionality of the "To:" box on Gmail but of course in .NET.


Have you looked into the Ajax Control Toolkit?

http://www.asp.net/AJAX/AjaxControlToolkit/Samples/AutoComplete/AutoComplete.aspx


In control (for example TextBox) Properties tab, open Behavior section and set AutoCompleteType to needed value. You can do the same programatically. For your control (for example TextBox TextBox1) call AutoCompleteType type and initialize value (for example TextBox1.AutoCompleteType = AutoCompleteType.Email; )

0

精彩评论

暂无评论...
验证码 换一张
取 消