I have list, i want to convert it to autoCompleteStringCollection.. And I don't want use foreach.
_textbox.AutoCompleteMode = AutoCompleteMode.Append;
_textbox.AutoCompleteSource = AutoCompleteSource.CustomSource;
_textbox.AutoCompleteCustomSource = user.GetNameUsers() as AutoCompleteStringCollection;
Note user.GetNameUsers() is list.
Code doesn't work, it become null.
Thank you
_textbox.AutoCompleteMode = AutoCompleteMode.Append;
_textbox.AutoCompleteSource = AutoCompleteSource.CustomSource;
var autoComplete = new AutoCompleteStringCollection();
autoComplete.AddRange(user.GetNameUsers().ToArray());
_textbox.AutoCompleteCustomSource = autoComplete;
If you need this often, you can write an extension method:
public static class EnumerableExtensionsEx
{
public static AutoCompleteStringCollection ToAutoCompleteStringCollection(
this IEnumerable<string> enumerable)
{
if(enumerable == null) throw new ArgumentNullException("enumerable");
var autoComplete = new AutoCompleteStringCollection();
foreach(var item in enumerable) autoComplete.Add(item);
return autoComplete;
}
}
Usage:
_textbox.AutoCompleteCustomSource = user.GetUsers().ToAutoCompleteStringCollection();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With