Highlighted
Absent Member.
Absent Member.
2027 views

Array not populating correctly in datagrid

Jump to solution

HI, I have a cobol program which returns me the array in a copybook when I pass that copy book to form and try to load that array in datagridview the value is getting changed.

e.g  The Copy Book Variable is declared

01 S PIC S9(9)V99 occurs 15 times

and when I am binding it to grid inside a loop

invoke dgv::Rows::Add(S(counter))

0 Likes
2 Solutions

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

The default format for a column is simply a text format so numeric data will not contain any formatting characters such as decimal points, commas etc.

In order to get the columns to be formatted correctly you need to set the DefaultCellStyle::Format property. You can do this within the Forms Designer by editing the column and clicking on the DefaultCellStyle option and populating the Format property with a predefined type or with a custom formatting mask.

You can also do this within code like:

          set dataGridView1::Columns::Item(0)::DefaultCellStyle::Format to "N2"

          perform varying sub1 from 1 by 1 until sub1 > 3

             invoke dataGridView1::Rows::Add(S(sub1))

          end-perform

N2 is the predefined type for numeric with 2 decimal places.

View solution in original post

0 Likes
Highlighted
Outstanding Contributor.
Outstanding Contributor.

S has PIC S9(9)V99 which is not a .Net object. Define S as decimal or move S before '::Rows::Add' to a decimal varialbe.

View solution in original post

0 Likes
5 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

The default format for a column is simply a text format so numeric data will not contain any formatting characters such as decimal points, commas etc.

In order to get the columns to be formatted correctly you need to set the DefaultCellStyle::Format property. You can do this within the Forms Designer by editing the column and clicking on the DefaultCellStyle option and populating the Format property with a predefined type or with a custom formatting mask.

You can also do this within code like:

          set dataGridView1::Columns::Item(0)::DefaultCellStyle::Format to "N2"

          perform varying sub1 from 1 by 1 until sub1 > 3

             invoke dataGridView1::Rows::Add(S(sub1))

          end-perform

N2 is the predefined type for numeric with 2 decimal places.

View solution in original post

0 Likes
Highlighted
Absent Member.
Absent Member.

Thanks the formatting issue is resolved but now if the value is 200.00 it is displaying as 20011.00 and if it is 16.25 then it is displaying as 1625.00

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

I am afraid that I will need to see an example in order to resolve this as I do not experience the same behavior here with a simple demo.

Can you attach a simple demo that demonstrates the problem?

0 Likes
Highlighted
Outstanding Contributor.
Outstanding Contributor.

S has PIC S9(9)V99 which is not a .Net object. Define S as decimal or move S before '::Rows::Add' to a decimal varialbe.

View solution in original post

0 Likes
Highlighted
Absent Member.
Absent Member.

thnx

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.