Hi,
I am using a creation filter to overlay an UltraCombo for all column headers in a grid. I am experiencing the same problem as this post: http://ko.infragistics.com/community/forums/p/43867/239732.aspx. The UltraCombo is appearing in the column header but the drop down does not open and allow me to select items. I have attached my creation filter code and a screen shot of the grid.
The UltraCombo allows me to set the SelectedRow and/or Text property fine. However, setting different Appearance properties in the creation filter has no effect (ie, combo.Appearance.ForeColor = Color.Indigo; below).
What am I missing? Any ideas? Thanks!
Here is the code:
internal class HeaderComboBoxCreationFilter : IUIElementCreationFilter
{
public void AfterCreateChildElements(UIElement parent)
if (parent is HeaderUIElement)
EditorWithComboUIElement comboBoxUIElement = null;
UltraGridComboEditorOwner embeddableEditor = null;
EditorWithCombo editor = null;
UltraCombo combo = null;
combo = new UltraCombo();
embeddableEditor = new UltraGridComboEditorOwner(combo);
editor = new EditorWithCombo(embeddableEditor);
comboBoxUIElement = new EditorWithComboUIElement(parent, embeddableEditor, editor, null, true, true, true, true);
combo.DataSource = CreateColumnDataTable();
combo.DisplayMember = "name";
combo.ValueMember = "value";
//combo.Text = "Text1";
combo.SelectedRow = combo.Rows[0];
combo.Appearance.ForeColor = Color.Indigo; // this does not have an effect
combo.DropDownStyle = UltraComboStyle.DropDown;
combo.DropDownButtonDisplayStyle = Infragistics.Win.ButtonDisplayStyle.Always;
comboBoxUIElement.Rect = parent.Rect;
parent.ChildElements.Add(comboBoxUIElement);
}
private DataTable CreateColumnDataTable()
DataTable dataTable = new DataTable();
dataTable.Columns.Add("name", typeof(string));
dataTable.Columns.Add("value", typeof(string));
dataTable.Rows.Add(new object[] { "Name1", "Value1" });
dataTable.Rows.Add(new object[] { "Name2", "Value2" });
dataTable.AcceptChanges();
return dataTable;
public bool BeforeCreateChildElements(UIElement parent)
return false;
I don't think this approach will work. The UltraCombo UIElement you are creating isn't associated with the grid control, it's associated with the UltraCombo you created in code, so it this is going to cause all sorts of weird behavior.
What I would do is skip all that. Don't bother creating a UIElement. Just position the actual UltraCombo control over the header.
Something like this:
public void AfterCreateChildElements(UIElement parent) { if (parent is HeaderUIElement) { //EditorWithComboUIElement comboBoxUIElement = (EditorWithComboUIElement)parent.GetDescendant(typeof(EditorWithComboUIElement)); //UltraGridComboEditorOwner embeddableEditor = null; //EditorWithCombo editor = null; //UltraCombo combo = null; UltraCombo combo = new UltraCombo(); //embeddableEditor = new UltraGridComboEditorOwner(combo); //editor = new EditorWithCombo(embeddableEditor); //comboBoxUIElement = new EditorWithComboUIElement(parent, embeddableEditor, editor, null, true, true, true, true); combo.DataSource = CreateColumnDataTable(); combo.DisplayMember = "name"; combo.ValueMember = "value"; //combo.Text = "Text1"; combo.SelectedRow = combo.Rows[0]; combo.Appearance.ForeColor = Color.Indigo; // this does not have an effect combo.DropDownStyle = UltraComboStyle.DropDown; combo.DropDownButtonDisplayStyle = Infragistics.Win.ButtonDisplayStyle.Always; //comboBoxUIElement.Rect = parent.Rect; //parent.ChildElements.Add(comboBoxUIElement); parent.Control.Controls.Add(combo); combo.Location = parent.Rect.Location; combo.Size = parent.Rect.Size; } }
Also... this has nothing to do with the issue, but this code you have here is extremely inefficient. The CreationFilter is going to get called a LOT and every time it does, you are creating a new UltraCombo control and you are never disposing it, so this application is going to leak memory like crazy. You should really try to re-use the same combo for each column. Maybe store the Combo in the column's Tag property.
Thanks, Mike. Your solution works nicely to get the UltraCombo in the column header with selectable items. With the UIElement approach, I was hoping to avoid having to resize the UltraCombos when a column size changes. Thanks for your memory leak tip. If I'm just overlaying controls onto the grid/form, then there is no benefit to using the IUIElementCreationFilter at all. I'll just build the UltraCombos when the form loads and keep their sizes in sync with the column sizes.