DataGrid: Autocomplete for the combobox column

Nov 3, 2008 at 6:13 PM
Edited Nov 3, 2008 at 6:13 PM
Can anyone please tell me whether it is possible to provide Autocomplete or autosuggest support for the Combobox column in the DataGrid v1.
Nov 3, 2008 at 7:42 PM

I did not see this feature in Combo Box column in DataGrid v1, but maybe I’m wrong; in regular Combo Box it handles by combination of properties IsReadOnly and IsEditable, see

http://msdn.microsoft.com/en-us/library/system.windows.controls.combobox.iseditable.aspx

What you can do, replace DataGridComboBoxColumn with DataGridTemplateColumn and for DataGridTemplateColumn.CellTemplate in DataTemplate have regular ComboBox with those properties set as you neded, and set Auto Complete feature as you want to.

                                   Thanks. Lena

Nov 3, 2008 at 8:07 PM
Yes i have been able to get the autocomplete feature in the regular combobox, if i could use that in the datagrid it would be great. Can you please explain with an example asto how i can use a regular combobox in a DataGridTemplateColumn. I am not very familiar with it. I can add the autocomplete part by my self, i just need to know how to add a regular combobox in a datagrid using DataGridTemplateColumn.

Thanks...
Coordinator
Nov 3, 2008 at 8:33 PM
You can also go through DataGridComboBoxColumn.EditingElementStyle to set IsEditable and IsReadOnly.
Coordinator
Nov 5, 2008 at 1:23 PM
Here is an example:

<dg:DataGridComboBoxColumn.EditingElementStyle>

                       <Style TargetType="ComboBox">

                           <Setter Property="IsEditable" Value="True" />

                       </Style>                    

</dg:DataGridComboBoxColumn.EditingElementStyle>

Nov 5, 2008 at 2:18 PM
Edited Nov 5, 2008 at 2:25 PM
Hello Vincent Sibal,
Thank you for ur reply, I have put the following message in ur blog also.
The thing is that when i set the editing element style in DataGridComboBoxColumn, it only enables me to be able to type in to the combobox, it does not filter the items in the combobox to display only the items matching the text being typed... I have been able to get this done in a regular combobox using the code shown below. Could you please help me as to how i can get the same feature here in the DataGridComboBoxColumn, possibly by modifying the code below?
Thank you.

myComboBox.ItemsSource = myItemsList;
myComboBox.IsEditable = true;
myComboBox.IsTextSearchEnabled = false;
myComboBox.Loaded += delegate
{
TextBox textBox = myComboBox.Template.FindName("PART_EditableTextBox", myComboBox) as TextBox;
Popup popup = myComboBox.Template.FindName("PART_Popup", myComboBox) as Popup;
if (textBox != null)
{
textBox.TextChanged += delegate
{
popup.IsOpen = true;
myComboBox.Items.Filter += a =>
{
myItems selectedItem = (myItems)a;
if (a.ToString().Contains(textBox.Text))
{
return true;
}
else
{
return false;
}
};
};
}
};