Question How to use datagridview

Hello,

I'm currently working to migrate from OE10 to OE12.8 and I have to rework every program that have OCX. I so choose to replace browse by DataGridView .

CLASS myClass INHERITS Form:
DEFINE PRIVATE VARIABLE myDG AS System.Windows.Forms.DataGridView NO-UNDO.

DEFINE BUFFER myDG-BUFFER FOR MYTABLE .
DEFINE QUERY myQUERIE FOR myDG-BUFFER SCROLLING .
DEFINE VARIABLE myBS AS Progress.Data.BindingSource NO-UNDO.

CONSTRUCTOR PUBLIC myClass:
InitializeComponent().
InitializeDataGridView() .


END CONSTRUCTOR .
METHOD PUBLIC VOID InitializeDataGridView( ):

/* Initialisation Spé Vignal */
QUERY myQUERIE:QUERY-PREPARE ("FOR EACH myDG-BUFFER NO-LOCK") .
QUERY myQUERIE:QUERY-OPEN() .
myBS = NEW Progress.Data.BindingSource() .
myBS:HANDLE = QUERY myQUERIE:HANDLE .
myBS:AllowEdit = FALSE .
myBS:AllowNew = FALSE .
myBS:AllowRemove = FALSE .
myDG:DataSource = myBS .
myDG:Columns["field2"]:visible = FALSE .


RETURN.

END METHOD.
END CLASS.



I manually hide the column I don't want to DISPLAY instead of keyeding the one I want like in a Browse WIDGET.

Am I doing right or is there another way ?

Best Regards,
 
Last edited by a moderator:
I am not sure of the actual problem, is it you want a way of hiding columns at different stages or only having required columns in the DataGridView?

If hiding columns you can loop through each column and based on the criteria hide that way:

Code:
DEFINE VARIABLE oDataGridViewColumn AS System.Windows.Forms.DataGridViewColumn NO-UNDO.
DEFINE VARIABLE vCount AS INTEGER NO-UNDO.

DO vCount = 0 TO myDG:ColumnCount - 1:
   oDataGridViewColumn = CAST(myDG:Columns[vCount], "System.Windows.Forms.DataGridViewColumn").
   IF oDataGridViewColumn:Name = "field2" AND // OR oDataGridViewColumn:Index = 3 AND
      oDataGridViewColumn:Visible = TRUE THEN
      oDataGridViewColumn:Visible = FALSE.
END.

If only wanting to have specified columns then there are a number of different ways and two very simple examples I can instantly think of:

Code:
myDG:Columns:Add("ColumnName1", "Column Label1").
myDG:Columns:Add("ColumnName2", "Column Label2").

Code:
DEFINE VARIABLE arrayvar AS Progress.Data.ColumnPropDesc EXTENT 4 NO-UNDO.

arrayvar[1] = NEW Progress.Data.ColumnPropDesc("cust-Num", "cust-Num", Progress.Data.DataType:INTEGER).
arrayvar[2] = NEW Progress.Data.ColumnPropDesc("Name", "Name", Progress.Data.DataType:CHARACTER).
arrayvar[3] = NEW Progress.Data.ColumnPropDesc("Address", "Address", Progress.Data.DataType:CHARACTER).
arrayvar[4] = NEW Progress.Data.ColumnPropDesc("city", "city", Progress.Data.DataType:CHARACTER).
myDG:Columns = arrayvar.
 
Sorry to not be clear and thank you for your reply .

It's not a matter of problem, but more like best practice to display TABLE/TEMP-TABLE in DataGridView wittout the requirment to hide everything .

I will try your way ;D Thanks
 
Back
Top