I have a UserControl that I want to embed in the UltraGrid. The UserControl contains an UltraComboEditor. To implement the IProvidesEmbeddedableEditor Interface, I added this:
#region IProvidesEmbeddableEditor Members public EmbeddableEditorBase Editor { get { return this.ultraComboEditor.Editor; } } #endregion
However, when I try to drop down the combobox that appears in the UltraGrid, the drop down list appears in the upper left part of the screen instead of under the combobox. What do I need to do to remedy this?
What you are doing here will not really embed your UserControl in the grid. All you are doing is using the editor from the UltraComboEditor control. If you want to do that, then you should just expose the UltraComboEditor control from your UserControl via a public property and then set the grid column's EditorControl to the UltraComboEditor.
So how can I really embed my UserControl?
I have my UserControl in the grid. To embed it I placed my UserControl dtpStamp on the form and made it not Visible. After it I put this code:
private void gridViewWaste_BeforeEnterEditMode(object sender, CancelEventArgs e){ // Use the BeforeEnterEditMode event to position the edit controls UltraGridCell objCell = this.gridViewWaste.ActiveCell; // This should be impossible, but its good practice to check // to make sure there is an active cell before continuing if (objCell == null) { return; } // Get the UIElement associated with the active cell, which we will // need so we can get the size and location of the cell if (objCell.IsDataCell && objCell.Column.Key == "Timestamp") { // Set the date picker's size and location equal to the active cell's size and location this.dtpStamp.SetBounds(left, top, dtpStamp.Width, dtpStamp.Height); // Set the value DateTime temp = DateTime.Parse(objCell.Value.ToString()); this.dtpStamp.Value = temp; this.dtpStamp.Visible = true; this.dtpStamp.Focus(); this.dtpStamp.BringToFront(); }}private void dtpStamp_Leave(object sender, EventArgs e){ // Use the BeforeEnterEditMode event to position the edit controls UltraGridCell objCell = this.gridViewWaste.ActiveCell; // This should be impossible, but its good practice to check // to make sure there is an active cell before continuing if (objCell == null) { return; } if (objCell.Column.Key == "Timestamp") { objCell.Value = dtpStamp.Value; }}
Also I hide my control in events like AfterColPosChanged, BeforeCellDeactivate...
You cannot embed a user control in the grid. The only things that can be embedded in a cell are editors. So you would have to derive a class from EmbeddableEditorBase. This is not a trivial process and I do not recommend it unless you have access to the Infragistics source code so you can use the existing editors as a guide.