Kbase P148897: How to bind a visual .net component to a prodataset
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  07/02/2011 |
|
Status: Unverified
GOAL:
How to bind a visual .net component to a prodataset
GOAL:
How to query database using prodataset and .net visual component
GOAL:
How to use probinding witth Prodaset and .net visual component
GOAL:
How to use prodataset with the new UI
FACT(s) (Environment):
OpenEdge 10.2x
Windows
FIX:
This simple application bellow, shows how to bind a prodataset to a visual component. This code is developed under the new UI, so it can be visually parsed within the OpenEdge Architect. In order to use it:
1 - Create a Project
2 - Connect to a sports database
3 - Create a class name ProbindingDataset and copy this source to its contents.
The key part of the code is the load method, where the probinding1 object sets its handle as the query handle, and create the tie from ABL data to .NET. Also is important to verify the names of the probinding schema. They match exactly the names of the database table and fields.
/*------------------------------------------------------------------------
File : ProbindingDataSet
Purpose :
Syntax :
Description :
Author(s) : cpacheco
Created : Fri May 29 13:15:06 EDT 2009
Notes :
----------------------------------------------------------------------*/
USING Progress.Lang.*.
USING Progress.Windows.Form.
CLASS ProbindingDataSet INHERITS Form :
DEFINE PRIVATE VARIABLE components AS System.ComponentModel.IContainer.
DEFINE PRIVATE VARIABLE bindingSource1 AS Progress.Data.BindingSource NO-UNDO.
DEFINE PRIVATE VARIABLE dataGridView1 AS System.Windows.Forms.DataGridView NO-UNDO.
DEFINE PRIVATE VARIABLE custNumDataGridViewTextBoxColumn AS System.Windows.Forms.DataGridViewTextBoxColumn NO-UNDO.
DEFINE PRIVATE VARIABLE nameDataGridViewTextBoxColumn AS System.Windows.Forms.DataGridViewTextBoxColumn NO-UNDO.
DEFINE PRIVATE VARIABLE addressDataGridViewTextBoxColumn AS System.Windows.Forms.DataGridViewTextBoxColumn NO-UNDO.
DEFINE PRIVATE VARIABLE cityDataGridViewTextBoxColumn AS System.Windows.Forms.DataGridViewTextBoxColumn NO-UNDO.
/*
*define the customer temp-table and datasets/datasources
*/
def temp-table tCustomer like Customer.
define dataset myDataset for tcustomer.
def data-source dsCustomer for customer .
CONSTRUCTOR PUBLIC ProbindingDataSet ( ):
SUPER().
InitializeComponent().
CATCH e AS Progress.Lang.Error:
UNDO, THROW e.
END CATCH.
END CONSTRUCTOR.
METHOD PRIVATE VOID InitializeComponent( ):
/* NOTE: The following method is generated by the OpenEdge Advanced GUI Visual Designer.
We strongly suggest that the contents of this method only be modified using the
Visual Designer to avoid any incompatible modifications.
Modifying the contents of this method using a code editor will invalidate any support for this file. */
@VisualDesigner.FormMember (NeedsInitialize="true").
DEFINE VARIABLE tableDesc1 AS Progress.Data.TableDesc NO-UNDO.
tableDesc1 = NEW Pr.ogress.Data.TableDesc("tCustomer").
THIS-OBJECT:bindingSource1 = NEW Progress.Data.BindingSource().
THIS-OBJECT:dataGridView1 = NEW System.Windows.Forms.DataGridView().
THIS-OBJECT:custNumDataGridViewTextBoxColumn = NEW System.Windows.Forms.DataGridViewTextBoxColumn().
THIS-OBJECT:nameDataGridViewTextBoxColumn = NEW System.Windows.Forms.DataGridViewTextBoxColumn().
THIS-OBJECT:addressDataGridViewTextBoxColumn = NEW System.Windows.Forms.DataGridViewTextBoxColumn().
THIS-OBJECT:cityDataGridViewTextBoxColumn = NEW System.Windows.Forms.DataGridViewTextBoxColumn().
CAST(THIS-OBJECT:bindingSource1, System.ComponentModel.ISupportInitialize):BeginInit().
CAST(THIS-OBJECT:dataGridView1, System.ComponentModel.ISupportInitialize):BeginInit().
THIS-OBJECT:SuspendLayout().
/* */
/* bindingSource1 */
/* */
tableDesc1:ChildTables = ?.
@VisualDesigner.FormMember (NeedsInitialize="false", InitializeArray="true").
DEFINE VARIABLE arrayvar0 AS Progress.Data.ColumnPropDesc EXTENT 4 NO-UNDO.
arrayvar0[1] = NEW Progress.Data.ColumnPropDesc("cust-Num", "cust-Num", Progress.Data.DataType:INTEGER).
arrayvar0[2] = NEW Progress.Data.ColumnPropDesc("Name", "Name", Progress.Data.DataType:CHARACTER).
arrayvar0[3] = NEW Progress.Data.ColumnPropDesc("Address", "Address", Progress.Data.DataType:CHARACTER).
arrayvar0[4] = NEW Progress.Data.ColumnPropDesc("city", "city", Progress.Data.DataType:CHARACTER).
tableDesc1:Columns = arrayvar0.
THIS-OBJECT:bindingSource1:TableSchema = tableDesc1.
/* */
/* dataGridView1 */
/* */
THIS-OBJECT:dataGridView1:AutoGenerateColumns = FALSE.
THIS-OBJECT:dataGridView1:ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode:AutoSize.
@VisualDesigner.FormMember (NeedsInitialize="false", InitializeArray="true").
DEFINE VARIABLE arrayvar1 AS System.Windows.Forms.DataGridViewColumn EXTENT 4 NO-UNDO.
arrayvar1[1] = THIS-OBJECT:custNumDataGridViewTextBoxColumn.
arrayvar1[2] = THIS-OBJECT:nameDataGridViewTextBoxColumn.
arrayvar1[3] = THIS-OBJECT:addressDataGridViewTextBoxColumn.
arrayvar1[4] = THIS-OBJECT:cityDataGridViewTextBoxColumn.
THIS-OBJECT:dataGridView1:Columns:AddRange(arrayvar1).
THIS-OBJECT:dataGridView1:DataSource = THIS-OBJECT:bindingSource1.
THIS-OBJECT:dataGridView1:Location = NEW System.Drawing.Point(149, 97).
THIS-OBJECT:dataGridView1:Nam.e = "dataGridView1".
THIS-OBJECT:dataGridView1:Size = NEW System.Drawing.Size(240, 150).
THIS-OBJECT:dataGridView1:TabIndex = 0.
/* */
/* custNumDataGridViewTextBoxColumn */
/* */
THIS-OBJECT:custNumDataGridViewTextBoxColumn:DataPropertyName = "cust-Num".
THIS-OBJECT:custNumDataGridViewTextBoxColumn:HeaderText = "cust-Num".
THIS-OBJECT:custNumDataGridViewTextBoxColumn:Name = "custNumDataGridViewTextBoxColumn".
/* */
/* nameDataGridViewTextBoxColumn */
/* */
THIS-OBJECT:nameDataGridViewTextBoxColumn:DataPropertyName = "Name".
THIS-OBJECT:nameDataGridViewTextBoxColumn:HeaderText = "Name".
THIS-OBJECT:nameDataGridViewTextBoxColumn:Name = "nameDataGridViewTextBoxColumn".
/* */
/* addressDataGridViewTextBoxColumn */
/* */
THIS-OBJECT:addressDataGridViewTextBoxColumn:DataPropertyName = "Address".
THIS-OBJECT:addressDataGridViewTextBoxColumn:HeaderText = "Address".
THIS-OBJECT:addressDataGridViewTextBoxColumn:Name = "addressDataGridViewTextBoxColumn".
/* */
/* cityDataGridViewTextBoxColumn */
/* */
THIS-OBJECT:cityDataGridViewTextBoxColumn:DataPropertyName = "city".
THIS-OBJECT:cityDataGridViewTextBoxColumn:HeaderText = "city".
THIS-OBJECT:cityDataGridViewTextBoxColumn:Name = "cityDataGridViewTextBoxColumn".
/* */
/* ProbindingDataSet */
/* */
THIS-OBJECT:ClientSize = NEW System.Drawing.Size(525, 541).
THIS-OBJECT:Controls:Add(THIS-OBJECT:dataGridView1).
THIS-OBJECT:Name = "ProbindingDataSet".
THIS-OBJECT:Text = "ProbindingDataSet".
THIS-OBJECT:Load:SUBSCRIBE(THIS-OBJECT:ProbindingDataSet_Load).
CAST(THIS-OBJECT:bindingSource1, System.ComponentModel.ISupportInitialize):EndInit().
CAST(THIS-OBJECT:dataGridView1, System.ComponentModel.ISupportInitialize):EndInit().
THIS-OBJECT:ResumeLayout(FALSE).
CATCH e AS Progress.Lang.Error:
UNDO, THROW e.
END CATCH.
END METHOD.
/*------------------------------------------------------------------------------
Purpose:
Notes: &n.bsp;
------------------------------------------------------------------------------*/
@VisualDesigner.
METHOD PRIVATE VOID ProbindingDataSet_Load( INPUT sender AS System.Object, INPUT e AS System.EventArgs ):
/** fills the dataset with data from the customer table */
def var hbuffer as handle.
hbuffer = Dataset myDataset:GET-BUFFER-HANDLE(1).
hbuffer:ATTACH-DATA-SOURCE (Data-source dsCustomer:handle,?,?,?).
dataset myDataset:fill().
/* ties the myDataset with the binding source. Visual components will now
show real alive data*/
THIS-OBJECT:bindingSource1:handle = dataset myDataset:handle.
RETURN.
END METHOD.
DESTRUCTOR PUBLIC ProbindingDataSet ( ):
IF VALID-OBJECT(components) THEN DO:
CAST(components, System.IDisposable):Dispose().
END.
END DESTRUCTOR.
END CLASS..