Highlighted
Absent Member.
Absent Member.
3056 views

listBox (sample C#)

In Visual Cobol i try:

- Create a listBox1

- Add Itens:

     invoke listBox1::"Items"::"Add"("Item 1")
            invoke listBox1::"Items"::"Add"("Item 2")

- But now, can i get INDEX from doubleClick event?

i try: invoke type MessageBox::Show(listBox1::Text), but, show only TEXT. But a need INDEX (0,1,2,3...)

Thanks.

Cláudio Miguel Müller

claudiomiguelmuller@hotmail.com

www.meugibi.com

0 Likes
5 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: listBox (sample C#)

Hi Claudio,

Please see the documentation for the Listbox class here as it lists all of the methods, properties and events that are available to you.

If this is a single selection Listbox then the following will return the selected index and display it in a textbox.

       class-id testlistselect.Form1 is partial
                 inherits type System.Windows.Forms.Form.
       
       working-storage section.
       
       method-id NEW.
       procedure division.
           invoke self::InitializeComponent
           goback.
       end method.

       method-id button1_Click final private.
       procedure division using by value sender as object e as type System.EventArgs.
            invoke listBox1::"Items"::"Add"("Item 1")
            invoke listBox1::"Items"::"Add"("Item 2")
            invoke listBox1::"Items"::"Add"("Item 3")
            invoke listBox1::"Items"::"Add"("Item 4")
       end method.

       method-id listBox1_SelectedIndexChanged final private.
       procedure division using by value sender as object e as type System.EventArgs.
       
           declare selIndex as binary-long = listBox1::SelectedIndex
           set textBox1::Text to selIndex::ToString
       
       end method.
      
       end class.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: listBox (sample C#)

you provided the link to the microsoft C # documentation.

there is the link to the documentation of methods for use in visual cobol?

Thanks.

Cláudio Miguel Müller

claudiomiguelmuller@hotmail.com

www.meugibi.com

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: listBox (sample C#)

Sorry, the .NET Framework classes are a Microsoft product and therefore they are documented by Microsoft.

When you use COBOL you are still accessing the same underlying .NET Framework classes and the methods, events and properties are all the same.

In COBOL you use a slightly different syntax than in C#.

You use the invoke statement to access methods without a returning value.

You use set or some other statement to access methods or properties that have a returning value.

Thanks,

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: listBox (sample C#)

How i try to use dataGridView. But i dont know to create column-names.

I try: (all whith errors)

      set dataGridView1::ColumnCount to 5 (OK)

         invoke dataGridView1::Columns::Add::"PriCol"

         invoke dataGridView1::Columns::Add('PriCol')

          invoke dataGridView1::"Columns"::"Add"::"PriCol"

          invoke dataGridView1::Columns::Add("PriCol")

Can i do this?

Thanks.

Cláudio Miguel Müller

claudiomiguelmuller@hotmail.com

www.meugibi.com

0 Likes
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: listBox (sample C#)

The Add method on the Columns collection property does not take a string as a parameter, it takes an object of type DataGridViewColumn.

You need to create the column objects first and then add them to the grid.

The easiest way to see how this is done is to let the designer do this for you and then look at the code that is generated (or just let the designer do it for you)

If you open up the datagridview tasks in design mode (click small arrow on top right of control) you will see a link named Add Columns. You can specify the details for each of the columns here.

The designer will then generate the required code and place it in the .designer.cbl file.

It should look something like the following:

      set dataGridView1 to new System.Windows.Forms.DataGridView
      set Column1 to new System.Windows.Forms.DataGridViewTextBoxColumn
      set Column2 to new System.Windows.Forms.DataGridViewTextBoxColumn
      set Column3 to new System.Windows.Forms.DataGridViewTextBoxColumn

and then further down there will be a method for adding these new columns to the grid:

invoke dataGridView1::Columns::AddRange(table of type System.Windows.Forms.DataGridViewColumn(Column1 Column2 Column3))

The column properties will then be set accordingly:

set Column1::HeaderText to "Column1"
set Column1::MaxInputLength to 10
set Column1::Name to "Column1"

 *> Column2

set Column2::HeaderText to "Column2"
set Column2::MaxInputLength to 10
set Column2::Name to "Column2"

etc.

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.