I wanted to have an extension method to Combobox control which suggest the combobox list items by any part of the string. rather than the first part of the list items. i have done some coding but which is failing
(1) Auto suggest not appearing
(2) Combo box texts are over writing, i mean only one character remaining in the text field.
(3) Some times, the Horrible Happens
System.AccessViolationException: 'Attempted to read or write protected memory. This is often an indication that other memory is corrupt.'
C# Code:
public static void AutoCompleteByAnyString(this ToolStripComboBox CboBx,
DataTable SourceTable,
string Q )
{
if (Q.Length > 0 && SourceTable != null)
{
var Fs = (from Dr in SourceTable.AsEnumerable()
where Dr.Field<String>("Fs").Contains(Q.ToUpper())
select Dr [CboBx.ComboBox.DisplayMember]).ToArray();
AutoCompleteStringCollection A = new AutoCompleteStringCollection();
foreach (var item in Fs)
{
A.Add(item.ToString());
}
CboBx.AutoCompleteSource = AutoCompleteSource.CustomSource;
CboBx.AutoCompleteCustomSource = A;
CboBx.AutoCompleteMode = AutoCompleteMode.Suggest;
} else
{
CboBx.AutoCompleteSource = AutoCompleteSource.ListItems;
CboBx.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
}
}
[COLOR=#242729][FONT=Arial][/FONT][/COLOR]
The above code should have displayed the suggested list items in the combobox.
Note: i am using VS2019