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.
Actually, using the CreationFilter is still a good idea, because then you don't have to deal with the column resizing, scrolling, moving, etc.
The CreationFilter will fire any time any of those things happen, so it's a good centralized place to do what you want.
Hi Steve,
Just something to keep in mind about using the Tag property - if you are just showing flat data in the grid, that's fine. But if you decide to do this on a child band, or you are letting your user use OutlookGroupBy to group the data, then it's possible for a single column to display more than one header. The column headers would appear under each parent row. So if you allow grouping or hierarchical data, using the tag of the column probably won't work, since you will need more than one combo per column. And then there is, of course, the added complication of keeping multiple combos in synch. :)
Mike,
Yes, you are absolutely right. The creation filter is the way to go and I am able to resize the UltraCombo on column resizes. I'm sticking the combo in the column header Tag property and everything works great.
Thanks again,Steve