Kbase P162520: How to add a new UltraGrid row in a dialog rather than directly in the grid
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  5/7/2010 |
|
Status: Unverified
GOAL:
How to add a new UltraGrid row in a dialog rather than directly in the grid
GOAL:
How to update a non-updatable UltraGrid using a dialog
FACT(s) (Environment):
Windows
OpenEdge 10.2x
FIX:
Although an UltraGrid has the capability to allow data entry directly into the grid rows, it is also possible to update it programmatically using values obtained elsewhere. The following example shows how to update an UltraGrid row based on information entered into an "add" dialog. For the sake of simplicity, code to update the underlying data source from the UltraGrid is not shown here. Also for the sake of simplicity, the grid has only one band ("Customer"). The UltraGrid is assumed to be populated with records from the Customer table of Sports2000.
In the form containing the UltraGrid, use the UltraGrid DoubleClickRow event handler to invoke the "add" dialog when a row is double-clicked:
METHOD PRIVATE VOID ultraGridCustomer_DoubleClickRow(
INPUT sender AS System.Object, INPUT e AS Infragistics.Win.UltraWinGrid.DoubleClickRowEventArgs ):
DEFINE VARIABLE rAddDialog AS DemoAddDialog NO-UNDO.
/* Instantiate the dialog object, pass the Customer band as the container for the new row, and wait for the dialog to complete. */
rAddDialog = NEW DemoAddDialog(ultraGridCustomer:DisplayLayout:Bands["Customer"]).
WAIT-FOR rAddDialog:ShowDialog().
RETURN.
The code for the "add" dialog follows:
USING Progress.Windows.Form.
USING Infragistics.Win.UltraWinGrid.*.
CLASS DemoAddDialog INHERITS Form :
DEFINE PRIVATE VARIABLE components AS System.ComponentModel.IContainer NO-UNDO.
DEFINE PRIVATE VARIABLE buttonOk AS System.Windows.Forms.Button NO-UNDO.
DEFINE PRIVATE VARIABLE buttonCancel AS System.Windows.Forms.Button NO-UNDO.
DEFINE PRIVATE VARIABLE inputCustNum AS Infragistics.Win.UltraWinEditors.UltraTextEditor NO-UNDO.
DEFINE PRIVATE VARIABLE ultraLabel1 AS Infragistics.Win.Misc.UltraLabel NO-UNDO.
/* Class-level variable for referencing the band that will contain the new row. */
DEFINE PRIVATE VARIABLE rContainingBand AS UltraGridBand NO-UNDO.
CONSTRUCTOR PUBLIC DemoAddDialog( prBand AS UltraGridBand ):
SUPER().
InitializeComponent ( ).
/* Save the reference to the band that will contain the new row. This will be needed
when the row is added to the grid after data entry is complete.
*/
rContainingBand = prBand.
CATCH e AS Progress.Lang.Error:
UNDO, THROW e.
END CATCH.
END CONSTRUCTOR.
DESTRUCTOR PUBLIC DemoAddDialog( ):
IF VALID-OBJECT(components) THEN DO:
CAST(components, System.IDisposable):Dispose().
END.
END DESTRUCTOR.
METHOD PRIVATE VOID okButton_Click (sender AS System.Object, e AS System.EventArgs):
/* .A new UltraGridRow is a separate object that must be instantiated */
DEFINE VARIABLE rNewRow AS UltraGridRow NO-UNDO.
/* Add the new row when the user has finished entering data and presses the
OK button.
*/
rNewRow = rContainingBand:AddNew().
/* Set each cell in the new row with the value that the user entered. These are
text values that are analogous to the SCREEN-VALUE attribute of a traditional
ABL widget. Only the CustNum field is demonstrated here; a line must be added
for each field for which the user was allowed to enter data.
*/
rNewRow:Cells['CustNum']:Value = inputCustNum:Text.
THIS-OBJECT:DialogResult = System.Windows.Forms.DialogResult:Ok.
THIS-OBJECT:Close ( ).
END METHOD.
METHOD PRIVATE VOID cancelButton_Click (sender AS System.Object, e AS System.EventArgs):
THIS-OBJECT:DialogResult = System.Windows.Forms.DialogResult:Cancel.
THIS-OBJECT:Close ( ).
END METHOD.
METHOD PRIVATE VOID InitializeComponent ( ): /* not shown */
...
METHOD PUBLIC VOID ShowModalDialog( ):
WAIT-FOR THIS-OBJECT:ShowDialog().
END METHOD.
END CLASS..