Big news! The community will be moving to a new platform April 21. Read more.
Big news! The community will be moving to a new platform April 21. Read more.
Commodore
Commodore
1479 views

DataGrid

Jump to solution

Is it possible to use the "Create Collection" to fill with DataGrid? How do it?

0 Likes
1 Solution

Accepted Solutions
Micro Focus Expert
Micro Focus Expert

Yes you can use a bindingSource to bind the dataGridView to a collection list in the same manner as I showed earlier for a combobox.

I am attaching a demo which binds the dataGridView to a collection list which is filled with objects of the gridData class. Since this class exposes its fields as properties they can individually be bound as columns within the dataGridView control. If you look at the columns defined for dataGridView1 you will see that the DataMember properties are set to these property names within the gridData class.

The following is the source code used in the project:

       class-id bindwingrid.Form1 is partial
                 inherits type System.Windows.Forms.Form.
       
       working-storage section.
       
       method-id NEW.
       procedure division.
           invoke self::InitializeComponent
           declare fl as type fillList = new fillList
           set bindingSource1::DataSource to fl::getList
           set dataGridView1::DataSource to bindingSource1::DataSource
           goback.
       end method.

       method-id button1_Click final private.
       procedure division using by value sender as object e as type System.EventArgs.
           invoke self::Close
       end method.
      
       end class.
       class-id gridData.
       
       working-storage section.
       01 custNo       binary-long property.
       01 custName     string property.
       01 custCompany string property.
       
       end class.
       class-id fillList.
           select item-file assign to "C:\bindwingrid\bindwingrid\itemfile.txt"
                            organization is line sequential
                            file status is file-status.
       file section.
       fd item-file.
       01 item-record.
          05 cust-no      pic 9(3).
          05 cust-name    pic x(20).
          05 cust-company pic x(20).
       
       working-storage section.
       01 file-status  pic x(2) value spaces.
       method-id getList.
       local-storage section.
       procedure division returning mylist as list[type gridData].
       
           open input item-file
           create mylist
       
           perform until exit
              read item-file
                 at end
                    exit perform
                 not at end
                    declare myitem as type gridData = new gridData
                    set myitem::custNo to cust-no
                    set myitem::custName to cust-name
                    set myitem::custCompany to cust-company
                    write mylist from myitem
              end-read
           end-perform
           close item-file
           goback.
           
       end method.
        
       end class.

View solution in original post

0 Likes
4 Replies
Micro Focus Expert
Micro Focus Expert

Are you referring to a DataGridView control?

0 Likes
Commodore
Commodore

Yes!

0 Likes
Micro Focus Expert
Micro Focus Expert

Yes you can use a bindingSource to bind the dataGridView to a collection list in the same manner as I showed earlier for a combobox.

I am attaching a demo which binds the dataGridView to a collection list which is filled with objects of the gridData class. Since this class exposes its fields as properties they can individually be bound as columns within the dataGridView control. If you look at the columns defined for dataGridView1 you will see that the DataMember properties are set to these property names within the gridData class.

The following is the source code used in the project:

       class-id bindwingrid.Form1 is partial
                 inherits type System.Windows.Forms.Form.
       
       working-storage section.
       
       method-id NEW.
       procedure division.
           invoke self::InitializeComponent
           declare fl as type fillList = new fillList
           set bindingSource1::DataSource to fl::getList
           set dataGridView1::DataSource to bindingSource1::DataSource
           goback.
       end method.

       method-id button1_Click final private.
       procedure division using by value sender as object e as type System.EventArgs.
           invoke self::Close
       end method.
      
       end class.
       class-id gridData.
       
       working-storage section.
       01 custNo       binary-long property.
       01 custName     string property.
       01 custCompany string property.
       
       end class.
       class-id fillList.
           select item-file assign to "C:\bindwingrid\bindwingrid\itemfile.txt"
                            organization is line sequential
                            file status is file-status.
       file section.
       fd item-file.
       01 item-record.
          05 cust-no      pic 9(3).
          05 cust-name    pic x(20).
          05 cust-company pic x(20).
       
       working-storage section.
       01 file-status  pic x(2) value spaces.
       method-id getList.
       local-storage section.
       procedure division returning mylist as list[type gridData].
       
           open input item-file
           create mylist
       
           perform until exit
              read item-file
                 at end
                    exit perform
                 not at end
                    declare myitem as type gridData = new gridData
                    set myitem::custNo to cust-no
                    set myitem::custName to cust-name
                    set myitem::custCompany to cust-company
                    write mylist from myitem
              end-read
           end-perform
           close item-file
           goback.
           
       end method.
        
       end class.

View solution in original post

0 Likes
Commodore
Commodore

Thank you

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.