I need to dynamically set a column in an UltraDropDown based on a value in the UltraGrid row from which it is being dropped. In other words I want to get a reference to either the UltraGridRow or the UltraGridCell which was clicked on, to use in the InitializeRow event of the UltraDropDown.
It isn't an parent control and I can't seem to find any combination of UIElements which would help out.
Things like
UltraDropDown u = UltraDropDown(sender);
UIElement element = u.DisplayLayout.UIElement;
element.GetAncestor(....... GetContext(.
None of the above lead anywhere. Other than a hoaky getting a client by assuming the point is above the dropdown and using something like ElementFromPoint, does anyone have any way to get the UltraGrid row or cell dropping down the list?
Hmm after posting this, I realized that the cell and row should be active, so I should be able to get them indirectly. Be better of course if there was a more direct way.
Okay, it looks like this does not work with an UltraDropDown, it only works with editor buttons.
If you just want to display a dropdown list for information and not let the user choose from the list or edit the cell, then you can do this:
Add an UltraTextEditor to the form with the grid.
Instead of an UltraDropDown, use another UltraGrid.
Use the ButtonsRight collection of the UltraTextEditor and add a DropDownEditorButton to it. Set the Control property of the button to the second grid.
Then set the EditorControl property of the grid column to the UltraTextEditor. This gives you a dropdown grid in the cell.
Now you can set the CellActivation to ActiveOnly and the ButtonDisplayStyle to Always and the user can drop down the grid within the grid.
An interesting bonus to this is that the grid on the dropdown is UI active. So you could allow the users to filter or sort it. You could put summaries on it, etc. You could even make it editable.
I tried both NoEdit and ActivateOnly and while the button displays, it does nothing when you click it, so it appears that AllowEdit is the only case where the dropdown appears. That is unless there is some combination of other properties which I have set which is disallowing it.
I tried playing with CellClickAction (set to Edit) and CellDisplayStyle (set to FullEditorDisplay) in case the defaults were overridden but they didn't help either.
Couldn't see anything else that could effect it.
I think if you set CellActivation on the column to NoEdit (or maybe ActivateOnly) and then set the column's ButtonDislpayStyle to Always, it might also work the way you want.
Before I mislead anyone reading this thread about using the UltraDropDown as a informational display only, it wasn't as easy as I thought. The cell has to be editable before the list drops down. This causes a row selected in the dropdown to update the grid cell value as the list is closed even though I didn't want it to and even though I don't have either a ValueMember or DisplayMember set.
The list of things I had to do to get the UltraDropDown as a display only auxillary grid of information was the following:
In the Grid BeforeCellListDropDown event, set the datasource and then add a statement with a switch on the cell key. (stops painting otherwise there is a visual glitch as the grid cell is updated and then repainted back to it's original value)
grid.BeginUpdate();
In the Grid CellListSelect event, add a statement with a switch on the cell key. (causes the cell update when the list collapses to be cancelled)
e.Cell.CancelUpdate();
In the Grid AfterCellListCloseUp event, add a statement with a switch on the cell key. (allows painting to resume again)
grid.EndUpdate()
In the DropDown RowSelected event, add a statement to prevent a row in the dropdown from being selected (information only - no need to highlight)
if (e.Row != null) e.Row.Selected = false;
All this allowed me to achieve my objective and was not as straight forward as alluded to in the first posts.
Incidentally in working through this I came across the way to find the row or cell that drops down the list from the UltraDropDown. The RowSelected event (and others) in the UltraDropDown provide an e.Owner property which is the UltraGrid that dropped down the list. Not that useful now since I knew which grid dropped down the list and grid.ActiveCell worked out for me, but available if necessary as the Owner of the control, if you were doing something dynamic and didn't know the owner of the UltraDropDown.
Nuff said. ActiveCell it is... I think I was just looking to understand how the UltraDropDown was attached to the cell, and the IValueList interface is a good enough answer.