Consultor Eletrônico



Kbase P153770: How to position the ColumnChooserDialog next to the ColumnChooserButton
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   10/13/2009
Status: Unverified

GOAL:

How to position the ColumnChooserDialog next to the ColumnChooserButton

GOAL:

How to locate the UltraGrid ColumnChooserButton in a form

GOAL:

How to use UltraGrid UIElements classes to control the startup position of the ColumnChooser dialog

FACT(s) (Environment):

Windows
OpenEdge 10.2x

FIX:

The UltraGrid ColumnChooserDialog is a wrapper class that displays the ColumnChooser control as a Windows Forms dialog. Its default startup location is FormStartPosition:WindowsDefaultLocation, which tells the operating system to compute the best location for the form at startup based on the current hardware.
One way to allow the user to display the ColumnChooser is to place a ColumnChooserButton in the RowSelectorHeader. To do this, set the DisplayLayout:Override:RowSelectorHeaderStyle property of the UltraGrid to Infragistics:Win:UltraWinGrid:RowSelectorHeaderStyle:ColumnChooserButton or ColumnChooserButtonFixedSize. This can be done in OpenEdge Visual Designer using the Properties sheet of the UltraGrid, or in code.
If it is desired to have the ColumnChooser appear at a known location near the ColumnChooserButton, add code similar to the following to the BeforeColumnChooserDisplayed event handler:

DEFINE VARIABLE rUltraGrid AS UltraGrid NO-UNDO.
DEFINE VARIABLE rUIElement AS UIElement NO-UNDO.
DEFINE VARIABLE rColumnChooserButton AS RowSelectorHeaderUIElement NO-UNDO.

rUltraGrid = CAST(sender, UltraGrid).


/*
Use UIElements to manipulate the graphical representation of objects on the screen.
The element chain for this grid under UltraGrid:DisplayLayout is:
ChildElements[1] DataAreaUIElement The data area of the grid (below the group-by box)
ChildElements[0] RowColRegionIntersectionUIElement The rows and columns, but not the scrollbars
ChildElements[1] BandHeadersUIElement The header row
ChildElements[3] RowSelectorHeaderUIElement The column chooser button
If there is a ColumnChooserButton to fire an event for this handler, all of the above elements should
exist. If any of these are not found, the method will simply return without setting the column chooser
location, and the default location will be used.
*/

/* The main UIElement always exists. */
rUIElement = rUltraGrid:DisplayLayout:UiElement.
/* Drill down the UIElement chain to reach the RowSelectorHeaderUIElement, which was set to be a
ColumnChooserButton. This version does not support multiple bands. It could be made to do so
by storing the types to be searched for at each level in an array, and modifying findChildUIElement
to call itself recursively. */
rUIElement = findChildUIElement(rUIElement, 'Infragistics.Win.UltraWinGrid.DataAreaUIElement').
IF (rUIElement = ?) THEN
RETURN.
rUIElement = findChildUIElement(rUIElement, 'Infragistics.Win.UltraWinGrid.RowColRegionIntersectionUIElement').
IF (rUIElement = ?) THEN
RETURN.
rUIElement = findChildUIElement(rUIElement, 'Infragistics.Win.UltraWinGrid.BandHeadersUIElement').
IF (rUIElement = ?) THEN
RETURN.
rUIElement = findChildUIElement(rUIElement, 'Infragistics.Win.UltraWinGrid.RowSelectorHeaderUIElement').
IF (rUIElement = ?) THEN
RETURN.

rColumnChooserButton = CAST(rUIElement, RowSelectorHeaderUIElement).

/* R> FormStartPosition:Manual starts the ColumnChooserDialog at (0,0) relative to the form,
and allows the Location property to control where the dialog appears. The default value
for FormStartPosition is WindowsDefault, which does not give you a known starting point
for the dialog and does not honor the Location property.
*/
e:Dialog:StartPosition = FormStartPosition:Manual.

/*
Translate the top right corner of the column chooser button from client coordinates
into screen coordinates, and use that location for the top left corner of the dialog.
*/

e:Dialog:Location =
rUltraGrid:PointToScreen(NEW System.Drawing.Point(rColumnChooserButton:Rect:Right,
rColumnChooserButton:Rect:Top)).
The helper method findChildUIElement is used to walk the UIElement tree in order to find the ColumnChooserButton:

/*
findChildUIElement
Find the first child of the given UIElement that is of the requested type. If no such child is
found, return a null reference. Does not support multiple bands.
*/


METHOD PRIVATE UIElement findChildUIElement(INPUT rUIElement AS UIElement, INPUT cType AS CHARACTER ):
DEFINE VARIABLE rChild AS UIElement NO-UNDO.
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DEFINE VARIABLE iLastIndex AS INTEGER NO-UNDO.


IF rUIElement:HasChildElements THEN DO:
iLastIndex = rUIElement:ChildElements:Count - 1.
DO i = 0 TO iLastIndex:rChild = rUIElement:ChildElements[i].
IF (rChild:GetType() = TypeHelper:GetType(cType)) THEN
RETURN rChild.
END.
END.
ELSE DO:
MESSAGE 'ultraGrid2_BeforeColumnChooserDisplayed: Unexpected error' VIEW-AS ALERT-BOX.
RETURN ?.
END.

END METHOD..