Skip to main content

My list view is populated initially thanks to the forum.  I need to be able to select the the first line in the list view now and return the data so I know the SiteListNum.  The examples for the listbox on the forum don't seem to work correctly for me with list view.  Can anyone provide an example?  My code is below:

*>PopulateListbox method      

method-id PopulateListbox final private.

local-storage section.

01 SiteList.

   05 SiteListDesc  pic x(40)   value spaces.

   05 SiteListNum   pic x(4)    value spaces.

01 indexOfSelection binary-long value 0.

01 row type ListViewItem.

procedure division.

    if ds-return = spaces

       invoke listView1::BeginUpdate

       perform varying idx from 1 by 1 until idx > 99

           if lb-siteentry(idx) > spaces

               set row to new ListViewItem(LB-SITEENTRY-DESC(idx))

               invoke row::SubItems::Add(LB-SITEENTRY-NUM(idx))

               invoke listView1::Items::Add(row)

           else

               exit perform   

           end-if

       end-perform

      

       *> set the selected listbox item to first line

        move 0 to indexOfSelection

 

       *> get the selected listbox item

       

       invoke listView1::EndUpdate

    end-if

end method.

*>end PopulateListbox method


#ListView
#VisualCOBOL
#SubItems
#VisualStudio

My list view is populated initially thanks to the forum.  I need to be able to select the the first line in the list view now and return the data so I know the SiteListNum.  The examples for the listbox on the forum don't seem to work correctly for me with list view.  Can anyone provide an example?  My code is below:

*>PopulateListbox method      

method-id PopulateListbox final private.

local-storage section.

01 SiteList.

   05 SiteListDesc  pic x(40)   value spaces.

   05 SiteListNum   pic x(4)    value spaces.

01 indexOfSelection binary-long value 0.

01 row type ListViewItem.

procedure division.

    if ds-return = spaces

       invoke listView1::BeginUpdate

       perform varying idx from 1 by 1 until idx > 99

           if lb-siteentry(idx) > spaces

               set row to new ListViewItem(LB-SITEENTRY-DESC(idx))

               invoke row::SubItems::Add(LB-SITEENTRY-NUM(idx))

               invoke listView1::Items::Add(row)

           else

               exit perform   

           end-if

       end-perform

      

       *> set the selected listbox item to first line

        move 0 to indexOfSelection

 

       *> get the selected listbox item

       

       invoke listView1::EndUpdate

    end-if

end method.

*>end PopulateListbox method


#ListView
#VisualCOBOL
#SubItems
#VisualStudio

The following is an example which populates a 3 column listview with data and then sets the 2nd row to be the selected row and then when a button is clicked it will extract the columns from the first selected row into appropriate data items which in this simple case are strings.

      class-id testlistview.Form1 is partial
                inherits type System.Windows.Forms.Form.
      working-storage section.
      method-id NEW.
      01 row type ListViewItem.
      procedure division.
          invoke self::InitializeComponent
          set row to new ListViewItem("R1Column1 Data")
          invoke row::SubItems::Add("R1Column2 Data")
          invoke row::SubItems::Add("R1Column3 Data")
          invoke listView1::Items::Add(row)
          set row to new ListViewItem("R2Column1 Data")
          invoke row::SubItems::Add("R2Column2 Data")
          invoke row::SubItems::Add("R2Column3 Data")
          invoke listView1::Items::Add(row)
          set row to new ListViewItem("R3Column1 Data")
          invoke row::SubItems::Add("R3Column2 Data")
          invoke row::SubItems::Add("R3Column3 Data")
          invoke listView1::Items::Add(row)
        *> sets second row in listview to be selected row as indexes are 0 based.
          set listView1::Items[1]::Selected to true
          goback.
      end method.

      method-id button1_Click final private.
      01 row type ListViewItem.
      01 column1 string.
      01 column2 string.
      01 column3 string.
      procedure division using by value sender as object e as type System.EventArgs.

     *>  You can set the columns directly using the SubItems property of the SelectedItems property.
     *>  There can be multiple selected items so [0] gets the first one.

          set column1 to listView1::SelectedItems[0]::SubItems[0]
          set column2 to listView1::SelectedItems[0]::SubItems[1]
          set column3 to listView1::SelectedItems[0]::SubItems[2]

     *>  Or you can do the following which gets the selected Row from the SelectedItems property and then gets the column from it.

          set row to listView1::SelectedItems[0]
          set column2 to row::SubItems[1]
          set column3 to row::SubItems[2]
          goback.

      end method.
      end class.


My list view is populated initially thanks to the forum.  I need to be able to select the the first line in the list view now and return the data so I know the SiteListNum.  The examples for the listbox on the forum don't seem to work correctly for me with list view.  Can anyone provide an example?  My code is below:

*>PopulateListbox method      

method-id PopulateListbox final private.

local-storage section.

01 SiteList.

   05 SiteListDesc  pic x(40)   value spaces.

   05 SiteListNum   pic x(4)    value spaces.

01 indexOfSelection binary-long value 0.

01 row type ListViewItem.

procedure division.

    if ds-return = spaces

       invoke listView1::BeginUpdate

       perform varying idx from 1 by 1 until idx > 99

           if lb-siteentry(idx) > spaces

               set row to new ListViewItem(LB-SITEENTRY-DESC(idx))

               invoke row::SubItems::Add(LB-SITEENTRY-NUM(idx))

               invoke listView1::Items::Add(row)

           else

               exit perform   

           end-if

       end-perform

      

       *> set the selected listbox item to first line

        move 0 to indexOfSelection

 

       *> get the selected listbox item

       

       invoke listView1::EndUpdate

    end-if

end method.

*>end PopulateListbox method


#ListView
#VisualCOBOL
#SubItems
#VisualStudio

set listView1::Items[0]::Selected to true... executes

set row to listView1::SelectedItems[0]... throws an exception (InvalidArgument=Value of '0' is not valid for 'index'.Parameter name: index.

set column1 to listView1::SelectedItems[0]::SubItems[0]          

set column2 to listView1::SelectedItems[0]::SubItems[1]          

set column3 to listView1::SelectedItems[0]::SubItems[2]... these three throw the same exception as above.  What ami I missing?

Code:

*>PopulateListbox method      

method-id PopulateListbox final private.

local-storage section.

01 column1 string.

01 column2 string.  

01 column3 string.

 

01 indexOfSelection binary-long value 0.

01 row type ListViewItem.

  

procedure division.

    if ds-return = spaces

       invoke listView1::BeginUpdate

       perform varying idx from 1 by 1 until idx > 99

           if lb-siteentry(idx) > spaces

               set row to new ListViewItem(LB-SITEENTRY-DESC(idx))

               invoke row::SubItems::Add(LB-SITEENTRY-NUM(idx))

               invoke listView1::Items::Add(row)

           else

               exit perform   

           end-if

       end-perform

      

       *> set the selected listbox item to first line, zero based

        set listView1::Items[0]::Selected to true

 

       *>test

        set column1 to listView1::SelectedItems[0]::SubItems[0]

        set column2 to listView1::SelectedItems[0]::SubItems[1]

        set column3 to listView1::SelectedItems[0]::SubItems[2]

      

       *> get the selected listbox item, zero based

        set row to listView1::SelectedItems[0]      

       

       *> get the selected listbox item, data is columns, zero based

        set row to listView1::SelectedItems[0]

        *>set DISP-SITE-DESC to row::SubItems[0]

        *>set DISP-SITE-ID to row::SubItems[1]

        set column2 to row::SubItems[0]

        set column3 to row::SubItems[1]

 

       invoke listView1::EndUpdate

    end-if

end method.

*>end PopulateListbox method

 

 


#SubItems
#VisualStudio
#ListView
#VisualCOBOL

My list view is populated initially thanks to the forum.  I need to be able to select the the first line in the list view now and return the data so I know the SiteListNum.  The examples for the listbox on the forum don't seem to work correctly for me with list view.  Can anyone provide an example?  My code is below:

*>PopulateListbox method      

method-id PopulateListbox final private.

local-storage section.

01 SiteList.

   05 SiteListDesc  pic x(40)   value spaces.

   05 SiteListNum   pic x(4)    value spaces.

01 indexOfSelection binary-long value 0.

01 row type ListViewItem.

procedure division.

    if ds-return = spaces

       invoke listView1::BeginUpdate

       perform varying idx from 1 by 1 until idx > 99

           if lb-siteentry(idx) > spaces

               set row to new ListViewItem(LB-SITEENTRY-DESC(idx))

               invoke row::SubItems::Add(LB-SITEENTRY-NUM(idx))

               invoke listView1::Items::Add(row)

           else

               exit perform   

           end-if

       end-perform

      

       *> set the selected listbox item to first line

        move 0 to indexOfSelection

 

       *> get the selected listbox item

       

       invoke listView1::EndUpdate

    end-if

end method.

*>end PopulateListbox method


#ListView
#VisualCOBOL
#SubItems
#VisualStudio

although set listView1::Items[0]::Selected to true... executes, when the form loads, the line is not highlighted??


My list view is populated initially thanks to the forum.  I need to be able to select the the first line in the list view now and return the data so I know the SiteListNum.  The examples for the listbox on the forum don't seem to work correctly for me with list view.  Can anyone provide an example?  My code is below:

*>PopulateListbox method      

method-id PopulateListbox final private.

local-storage section.

01 SiteList.

   05 SiteListDesc  pic x(40)   value spaces.

   05 SiteListNum   pic x(4)    value spaces.

01 indexOfSelection binary-long value 0.

01 row type ListViewItem.

procedure division.

    if ds-return = spaces

       invoke listView1::BeginUpdate

       perform varying idx from 1 by 1 until idx > 99

           if lb-siteentry(idx) > spaces

               set row to new ListViewItem(LB-SITEENTRY-DESC(idx))

               invoke row::SubItems::Add(LB-SITEENTRY-NUM(idx))

               invoke listView1::Items::Add(row)

           else

               exit perform   

           end-if

       end-perform

      

       *> set the selected listbox item to first line

        move 0 to indexOfSelection

 

       *> get the selected listbox item

       

       invoke listView1::EndUpdate

    end-if

end method.

*>end PopulateListbox method


#ListView
#VisualCOBOL
#SubItems
#VisualStudio

You need to display the listview on the form after setting the selected property before you can read the selecteditems property because at the point you are trying to get the selecteditems the listview control has not yet been created. This is why you are getting the index errors.

Also, the selected row will only be highlighted if the focus is set to the listview control when it is drawn.

invoke listView1::Focus

I am attaching my example that shows this working correctly.


My list view is populated initially thanks to the forum.  I need to be able to select the the first line in the list view now and return the data so I know the SiteListNum.  The examples for the listbox on the forum don't seem to work correctly for me with list view.  Can anyone provide an example?  My code is below:

*>PopulateListbox method      

method-id PopulateListbox final private.

local-storage section.

01 SiteList.

   05 SiteListDesc  pic x(40)   value spaces.

   05 SiteListNum   pic x(4)    value spaces.

01 indexOfSelection binary-long value 0.

01 row type ListViewItem.

procedure division.

    if ds-return = spaces

       invoke listView1::BeginUpdate

       perform varying idx from 1 by 1 until idx > 99

           if lb-siteentry(idx) > spaces

               set row to new ListViewItem(LB-SITEENTRY-DESC(idx))

               invoke row::SubItems::Add(LB-SITEENTRY-NUM(idx))

               invoke listView1::Items::Add(row)

           else

               exit perform   

           end-if

       end-perform

      

       *> set the selected listbox item to first line

        move 0 to indexOfSelection

 

       *> get the selected listbox item

       

       invoke listView1::EndUpdate

    end-if

end method.

*>end PopulateListbox method


#ListView
#VisualCOBOL
#SubItems
#VisualStudio

Many thanks Chris.


My list view is populated initially thanks to the forum.  I need to be able to select the the first line in the list view now and return the data so I know the SiteListNum.  The examples for the listbox on the forum don't seem to work correctly for me with list view.  Can anyone provide an example?  My code is below:

*>PopulateListbox method      

method-id PopulateListbox final private.

local-storage section.

01 SiteList.

   05 SiteListDesc  pic x(40)   value spaces.

   05 SiteListNum   pic x(4)    value spaces.

01 indexOfSelection binary-long value 0.

01 row type ListViewItem.

procedure division.

    if ds-return = spaces

       invoke listView1::BeginUpdate

       perform varying idx from 1 by 1 until idx > 99

           if lb-siteentry(idx) > spaces

               set row to new ListViewItem(LB-SITEENTRY-DESC(idx))

               invoke row::SubItems::Add(LB-SITEENTRY-NUM(idx))

               invoke listView1::Items::Add(row)

           else

               exit perform   

           end-if

       end-perform

      

       *> set the selected listbox item to first line

        move 0 to indexOfSelection

 

       *> get the selected listbox item

       

       invoke listView1::EndUpdate

    end-if

end method.

*>end PopulateListbox method


#ListView
#VisualCOBOL
#SubItems
#VisualStudio

Many thanks Chris.


My list view is populated initially thanks to the forum.  I need to be able to select the the first line in the list view now and return the data so I know the SiteListNum.  The examples for the listbox on the forum don't seem to work correctly for me with list view.  Can anyone provide an example?  My code is below:

*>PopulateListbox method      

method-id PopulateListbox final private.

local-storage section.

01 SiteList.

   05 SiteListDesc  pic x(40)   value spaces.

   05 SiteListNum   pic x(4)    value spaces.

01 indexOfSelection binary-long value 0.

01 row type ListViewItem.

procedure division.

    if ds-return = spaces

       invoke listView1::BeginUpdate

       perform varying idx from 1 by 1 until idx > 99

           if lb-siteentry(idx) > spaces

               set row to new ListViewItem(LB-SITEENTRY-DESC(idx))

               invoke row::SubItems::Add(LB-SITEENTRY-NUM(idx))

               invoke listView1::Items::Add(row)

           else

               exit perform   

           end-if

       end-perform

      

       *> set the selected listbox item to first line

        move 0 to indexOfSelection

 

       *> get the selected listbox item

       

       invoke listView1::EndUpdate

    end-if

end method.

*>end PopulateListbox method


#ListView
#VisualCOBOL
#SubItems
#VisualStudio

Many thanks Chris.


My list view is populated initially thanks to the forum.  I need to be able to select the the first line in the list view now and return the data so I know the SiteListNum.  The examples for the listbox on the forum don't seem to work correctly for me with list view.  Can anyone provide an example?  My code is below:

*>PopulateListbox method      

method-id PopulateListbox final private.

local-storage section.

01 SiteList.

   05 SiteListDesc  pic x(40)   value spaces.

   05 SiteListNum   pic x(4)    value spaces.

01 indexOfSelection binary-long value 0.

01 row type ListViewItem.

procedure division.

    if ds-return = spaces

       invoke listView1::BeginUpdate

       perform varying idx from 1 by 1 until idx > 99

           if lb-siteentry(idx) > spaces

               set row to new ListViewItem(LB-SITEENTRY-DESC(idx))

               invoke row::SubItems::Add(LB-SITEENTRY-NUM(idx))

               invoke listView1::Items::Add(row)

           else

               exit perform   

           end-if

       end-perform

      

       *> set the selected listbox item to first line

        move 0 to indexOfSelection

 

       *> get the selected listbox item

       

       invoke listView1::EndUpdate

    end-if

end method.

*>end PopulateListbox method


#ListView
#VisualCOBOL
#SubItems
#VisualStudio

Chris,

Thank you again.  Follow up question, the value returned below in { } is what I need to move into another data field, for example, site numer of 0001.  Is there a shortcut to just get the value enclosed in the braces or do I need to read the string in my cobol pgm for what is in the braces?  I don't see anything in the doc or the forum about this.


#SubItems
#VisualStudio
#VisualCOBOL
#ListView

My list view is populated initially thanks to the forum.  I need to be able to select the the first line in the list view now and return the data so I know the SiteListNum.  The examples for the listbox on the forum don't seem to work correctly for me with list view.  Can anyone provide an example?  My code is below:

*>PopulateListbox method      

method-id PopulateListbox final private.

local-storage section.

01 SiteList.

   05 SiteListDesc  pic x(40)   value spaces.

   05 SiteListNum   pic x(4)    value spaces.

01 indexOfSelection binary-long value 0.

01 row type ListViewItem.

procedure division.

    if ds-return = spaces

       invoke listView1::BeginUpdate

       perform varying idx from 1 by 1 until idx > 99

           if lb-siteentry(idx) > spaces

               set row to new ListViewItem(LB-SITEENTRY-DESC(idx))

               invoke row::SubItems::Add(LB-SITEENTRY-NUM(idx))

               invoke listView1::Items::Add(row)

           else

               exit perform   

           end-if

       end-perform

      

       *> set the selected listbox item to first line

        move 0 to indexOfSelection

 

       *> get the selected listbox item

       

       invoke listView1::EndUpdate

    end-if

end method.

*>end PopulateListbox method


#ListView
#VisualCOBOL
#SubItems
#VisualStudio

Sorry, I should have done this in the example:

Using the Text property will retrieve just the value of the column:

   if listView1::Created

       set row to listView1::SelectedItems[0]

       set column1 to row::SubItems[0]::Text

       set column2 to row::SubItems[1]::Text

       set column3 to row::SubItems[2]::Text

   end-if


My list view is populated initially thanks to the forum.  I need to be able to select the the first line in the list view now and return the data so I know the SiteListNum.  The examples for the listbox on the forum don't seem to work correctly for me with list view.  Can anyone provide an example?  My code is below:

*>PopulateListbox method      

method-id PopulateListbox final private.

local-storage section.

01 SiteList.

   05 SiteListDesc  pic x(40)   value spaces.

   05 SiteListNum   pic x(4)    value spaces.

01 indexOfSelection binary-long value 0.

01 row type ListViewItem.

procedure division.

    if ds-return = spaces

       invoke listView1::BeginUpdate

       perform varying idx from 1 by 1 until idx > 99

           if lb-siteentry(idx) > spaces

               set row to new ListViewItem(LB-SITEENTRY-DESC(idx))

               invoke row::SubItems::Add(LB-SITEENTRY-NUM(idx))

               invoke listView1::Items::Add(row)

           else

               exit perform   

           end-if

       end-perform

      

       *> set the selected listbox item to first line

        move 0 to indexOfSelection

 

       *> get the selected listbox item

       

       invoke listView1::EndUpdate

    end-if

end method.

*>end PopulateListbox method


#ListView
#VisualCOBOL
#SubItems
#VisualStudio

I saw an example of that in the VB forums online, tried to give it shot and I don't have the option:


#SubItems
#VisualCOBOL
#ListView
#VisualStudio

My list view is populated initially thanks to the forum.  I need to be able to select the the first line in the list view now and return the data so I know the SiteListNum.  The examples for the listbox on the forum don't seem to work correctly for me with list view.  Can anyone provide an example?  My code is below:

*>PopulateListbox method      

method-id PopulateListbox final private.

local-storage section.

01 SiteList.

   05 SiteListDesc  pic x(40)   value spaces.

   05 SiteListNum   pic x(4)    value spaces.

01 indexOfSelection binary-long value 0.

01 row type ListViewItem.

procedure division.

    if ds-return = spaces

       invoke listView1::BeginUpdate

       perform varying idx from 1 by 1 until idx > 99

           if lb-siteentry(idx) > spaces

               set row to new ListViewItem(LB-SITEENTRY-DESC(idx))

               invoke row::SubItems::Add(LB-SITEENTRY-NUM(idx))

               invoke listView1::Items::Add(row)

           else

               exit perform   

           end-if

       end-perform

      

       *> set the selected listbox item to first line

        move 0 to indexOfSelection

 

       *> get the selected listbox item

       

       invoke listView1::EndUpdate

    end-if

end method.

*>end PopulateListbox method


#ListView
#VisualCOBOL
#SubItems
#VisualStudio

It doesn't show in Intellisense, which is odd, but if you just type it in it will work.

I will look into this.


My list view is populated initially thanks to the forum.  I need to be able to select the the first line in the list view now and return the data so I know the SiteListNum.  The examples for the listbox on the forum don't seem to work correctly for me with list view.  Can anyone provide an example?  My code is below:

*>PopulateListbox method      

method-id PopulateListbox final private.

local-storage section.

01 SiteList.

   05 SiteListDesc  pic x(40)   value spaces.

   05 SiteListNum   pic x(4)    value spaces.

01 indexOfSelection binary-long value 0.

01 row type ListViewItem.

procedure division.

    if ds-return = spaces

       invoke listView1::BeginUpdate

       perform varying idx from 1 by 1 until idx > 99

           if lb-siteentry(idx) > spaces

               set row to new ListViewItem(LB-SITEENTRY-DESC(idx))

               invoke row::SubItems::Add(LB-SITEENTRY-NUM(idx))

               invoke listView1::Items::Add(row)

           else

               exit perform   

           end-if

       end-perform

      

       *> set the selected listbox item to first line

        move 0 to indexOfSelection

 

       *> get the selected listbox item

       

       invoke listView1::EndUpdate

    end-if

end method.

*>end PopulateListbox method


#ListView
#VisualCOBOL
#SubItems
#VisualStudio

One more list view question.  I have a button that successfully retrieves the selection in the list view when clicked (thanks).  I would like to execute the same code when the user simply clicks on a different selection in the listview (SelectedIndexChanged).  I added the event and thought I could just copy the code to this method and it would function the same way.  I get an index error in the event handler that I don't get in the button method.  Is the event handler a totally different animal?

 


#ListView
#VisualStudio
#SubItems
#VisualCOBOL

My list view is populated initially thanks to the forum.  I need to be able to select the the first line in the list view now and return the data so I know the SiteListNum.  The examples for the listbox on the forum don't seem to work correctly for me with list view.  Can anyone provide an example?  My code is below:

*>PopulateListbox method      

method-id PopulateListbox final private.

local-storage section.

01 SiteList.

   05 SiteListDesc  pic x(40)   value spaces.

   05 SiteListNum   pic x(4)    value spaces.

01 indexOfSelection binary-long value 0.

01 row type ListViewItem.

procedure division.

    if ds-return = spaces

       invoke listView1::BeginUpdate

       perform varying idx from 1 by 1 until idx > 99

           if lb-siteentry(idx) > spaces

               set row to new ListViewItem(LB-SITEENTRY-DESC(idx))

               invoke row::SubItems::Add(LB-SITEENTRY-NUM(idx))

               invoke listView1::Items::Add(row)

           else

               exit perform   

           end-if

       end-perform

      

       *> set the selected listbox item to first line

        move 0 to indexOfSelection

 

       *> get the selected listbox item

       

       invoke listView1::EndUpdate

    end-if

end method.

*>end PopulateListbox method


#ListView
#VisualCOBOL
#SubItems
#VisualStudio

There is an issue with a ListView in that when a selection changes the event is actually fired twice, once for the new selection and once for the deselection of the old selection. You must avoid reading the value when the event is fired for deselection as the index is invalid at that point.

I used the ItemSelectionChanged event instead of SelectedIndexChanged and check to see if the count of the SelectedItems collection is > 0 before reading the selection.

This works for a single selection listview but gets more complicated with a multiselection listview.

      method-id listView1_ItemSelectionChanged final private.

      01 row type ListViewItem.

      01 column1 string.

      01 column2 string.

      01 column3 string.

      procedure division using by value sender as object e as type System.Windows.Forms.ListViewItemSelectionChangedEventArgs.

           if listView1::SelectedItems::Count > 0

              set row to listView1::SelectedItems[0]

              set column1 to row::SubItems[0]::Text

              set column2 to row::SubItems[1]::Text

              set column3 to row::SubItems[2]::Text

              invoke listView1::Focus  

          end-if

       end method.


My list view is populated initially thanks to the forum.  I need to be able to select the the first line in the list view now and return the data so I know the SiteListNum.  The examples for the listbox on the forum don't seem to work correctly for me with list view.  Can anyone provide an example?  My code is below:

*>PopulateListbox method      

method-id PopulateListbox final private.

local-storage section.

01 SiteList.

   05 SiteListDesc  pic x(40)   value spaces.

   05 SiteListNum   pic x(4)    value spaces.

01 indexOfSelection binary-long value 0.

01 row type ListViewItem.

procedure division.

    if ds-return = spaces

       invoke listView1::BeginUpdate

       perform varying idx from 1 by 1 until idx > 99

           if lb-siteentry(idx) > spaces

               set row to new ListViewItem(LB-SITEENTRY-DESC(idx))

               invoke row::SubItems::Add(LB-SITEENTRY-NUM(idx))

               invoke listView1::Items::Add(row)

           else

               exit perform   

           end-if

       end-perform

      

       *> set the selected listbox item to first line

        move 0 to indexOfSelection

 

       *> get the selected listbox item

       

       invoke listView1::EndUpdate

    end-if

end method.

*>end PopulateListbox method


#ListView
#VisualCOBOL
#SubItems
#VisualStudio

To print the contents of the listview I need to increment the index of the row, I have it defined as below and have tried using [LVIdx] and [LVIdx 1] to increment the rows and print the data.  Right now, I can only print the the first record.  Is is the way I have LVIdx defined in WS?


#VisualStudio
#VisualCOBOL
#SubItems
#ListView

My list view is populated initially thanks to the forum.  I need to be able to select the the first line in the list view now and return the data so I know the SiteListNum.  The examples for the listbox on the forum don't seem to work correctly for me with list view.  Can anyone provide an example?  My code is below:

*>PopulateListbox method      

method-id PopulateListbox final private.

local-storage section.

01 SiteList.

   05 SiteListDesc  pic x(40)   value spaces.

   05 SiteListNum   pic x(4)    value spaces.

01 indexOfSelection binary-long value 0.

01 row type ListViewItem.

procedure division.

    if ds-return = spaces

       invoke listView1::BeginUpdate

       perform varying idx from 1 by 1 until idx > 99

           if lb-siteentry(idx) > spaces

               set row to new ListViewItem(LB-SITEENTRY-DESC(idx))

               invoke row::SubItems::Add(LB-SITEENTRY-NUM(idx))

               invoke listView1::Items::Add(row)

           else

               exit perform   

           end-if

       end-perform

      

       *> set the selected listbox item to first line

        move 0 to indexOfSelection

 

       *> get the selected listbox item

       

       invoke listView1::EndUpdate

    end-if

end method.

*>end PopulateListbox method


#ListView
#VisualCOBOL
#SubItems
#VisualStudio

You can use an iterator to automatically process a list or collection like the following:

Each time thru it automatically getsthe next occurrence without the need for an index.

The following will process all current items in the listview:

01 row type ListViewItem.

01 column1 string.

01 column2 string.

01 column3 string.

            perform varying row thru listView1::Items

               set column1 to row::SubItems[0]::Text

               set column2 to row::SubItems[1]::Text

               set column3 to row::SubItems[2]::Text

            end-perform


My list view is populated initially thanks to the forum.  I need to be able to select the the first line in the list view now and return the data so I know the SiteListNum.  The examples for the listbox on the forum don't seem to work correctly for me with list view.  Can anyone provide an example?  My code is below:

*>PopulateListbox method      

method-id PopulateListbox final private.

local-storage section.

01 SiteList.

   05 SiteListDesc  pic x(40)   value spaces.

   05 SiteListNum   pic x(4)    value spaces.

01 indexOfSelection binary-long value 0.

01 row type ListViewItem.

procedure division.

    if ds-return = spaces

       invoke listView1::BeginUpdate

       perform varying idx from 1 by 1 until idx > 99

           if lb-siteentry(idx) > spaces

               set row to new ListViewItem(LB-SITEENTRY-DESC(idx))

               invoke row::SubItems::Add(LB-SITEENTRY-NUM(idx))

               invoke listView1::Items::Add(row)

           else

               exit perform   

           end-if

       end-perform

      

       *> set the selected listbox item to first line

        move 0 to indexOfSelection

 

       *> get the selected listbox item

       

       invoke listView1::EndUpdate

    end-if

end method.

*>end PopulateListbox method


#ListView
#VisualCOBOL
#SubItems
#VisualStudio

You are a genius and this post should answer about everything anybody needs to know about list view code in Visual COBOL.  Thanks so much Chris, you are the man.  Unbelievably helpful.


My list view is populated initially thanks to the forum.  I need to be able to select the the first line in the list view now and return the data so I know the SiteListNum.  The examples for the listbox on the forum don't seem to work correctly for me with list view.  Can anyone provide an example?  My code is below:

*>PopulateListbox method      

method-id PopulateListbox final private.

local-storage section.

01 SiteList.

   05 SiteListDesc  pic x(40)   value spaces.

   05 SiteListNum   pic x(4)    value spaces.

01 indexOfSelection binary-long value 0.

01 row type ListViewItem.

procedure division.

    if ds-return = spaces

       invoke listView1::BeginUpdate

       perform varying idx from 1 by 1 until idx > 99

           if lb-siteentry(idx) > spaces

               set row to new ListViewItem(LB-SITEENTRY-DESC(idx))

               invoke row::SubItems::Add(LB-SITEENTRY-NUM(idx))

               invoke listView1::Items::Add(row)

           else

               exit perform   

           end-if

       end-perform

      

       *> set the selected listbox item to first line

        move 0 to indexOfSelection

 

       *> get the selected listbox item

       

       invoke listView1::EndUpdate

    end-if

end method.

*>end PopulateListbox method


#ListView
#VisualCOBOL
#SubItems
#VisualStudio

Hi

Thanks Chris for all your posts, in this an in others consults, I need use images listed/showed in a listbox, listview or other control.

I have seen in Microsoft msdn  "msdn.microsoft.com/.../system.windows.forms.listview.largeimagelist(v=vs.110).aspx", but I can't translate from C#  or other to Visual Cobol language.

thanks in advanced

Calisto H.


My list view is populated initially thanks to the forum.  I need to be able to select the the first line in the list view now and return the data so I know the SiteListNum.  The examples for the listbox on the forum don't seem to work correctly for me with list view.  Can anyone provide an example?  My code is below:

*>PopulateListbox method      

method-id PopulateListbox final private.

local-storage section.

01 SiteList.

   05 SiteListDesc  pic x(40)   value spaces.

   05 SiteListNum   pic x(4)    value spaces.

01 indexOfSelection binary-long value 0.

01 row type ListViewItem.

procedure division.

    if ds-return = spaces

       invoke listView1::BeginUpdate

       perform varying idx from 1 by 1 until idx > 99

           if lb-siteentry(idx) > spaces

               set row to new ListViewItem(LB-SITEENTRY-DESC(idx))

               invoke row::SubItems::Add(LB-SITEENTRY-NUM(idx))

               invoke listView1::Items::Add(row)

           else

               exit perform   

           end-if

       end-perform

      

       *> set the selected listbox item to first line

        move 0 to indexOfSelection

 

       *> get the selected listbox item

       

       invoke listView1::EndUpdate

    end-if

end method.

*>end PopulateListbox method


#ListView
#VisualCOBOL
#SubItems
#VisualStudio

Hi Calisto,

In the future please create new posts for new questions instead of adding them to the end of an existing thread.

Here is a COBOL example that I derived from the C# example show under LargeImageList.
This assumes that there is a ListView control called ListView1 already existing on your form.

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

       method-id createMyListView public.
       
       local-storage section.
       01 item1 type ListViewItem.
       01 item2 type ListViewItem.
       01 item3 type ListViewItem.
       01 liarray type ListViewItem occurs any.
       procedure division.

			*> Set the view to show details.
			set listView1::View to type View::Details
			*> Allow the user to edit item text.
			set listView1::LabelEdit to true
			*> Allow the user to rearrange columns.
			set listView1::AllowColumnReorder to true
			*> Display check boxes.
			set listView1::CheckBoxes to true
			*> Select the item and subitems when selection is made.
			set listView1::FullRowSelect to true
			*> Display grid lines.
			set listView1::GridLines to true
			*> Sort the items in the list in ascending order.
			set listView1::Sorting to type SortOrder::Ascending
            			
			*> Create three items and three sets of subitems for each item.
			set item1 to new ListViewItem("item1", 0)
			*> Place a check mark next to the item.
			set item1::Checked to true
			invoke item1::SubItems::Add("1")
			invoke item1::SubItems::Add("2")
			invoke item1::SubItems::Add("3")
			set item2 to new ListViewItem("item2", 1)
			invoke item2::SubItems::Add("4")
			invoke item2::SubItems::Add("5")
			invoke item2::SubItems::Add("6")
			set item3 to new ListViewItem("item3", 0)
			*> Place a check mark next to the item.
			set item3::Checked to true
			invoke item3::SubItems::Add("7")
			invoke item3::SubItems::Add("8")
			invoke item3::SubItems::Add("9")

			*> Create columns for the items and subitems.
			*> Width of -2 indicates auto-size.
			invoke listView1::Columns::Add("Item Column", -2, type HorizontalAlignment::Left)
			invoke listView1::Columns::Add("Column 2", -2, type HorizontalAlignment::Left)
			invoke listView1::Columns::Add("Column 3", -2, type HorizontalAlignment::Left)
			invoke listView1::Columns::Add("Column 4", -2, type HorizontalAlignment::Center)

			*>Add the items to the ListView.
            
            set content of liarray to (item1, item2, item3)
            invoke listView1::Items::AddRange(liarray)

			*> Create two ImageList objects.
			declare imageListSmall as type ImageList = new ImageList
            declare imageListLarge as type ImageList = new ImageList
            
			*> Initialize the ImageList objects with bitmaps.
			invoke imageListSmall::Images::Add(type Bitmap::FromFile("C:\\temp\\MySmallbmp.bmp"))
			invoke imageListSmall::Images::Add(type Bitmap::FromFile("C:\\temp\\MySmallbmp.bmp"))
			invoke imageListLarge::Images::Add(type Bitmap::FromFile("C:\\temp\\MyLargebmp.bmp"))
			invoke imageListLarge::Images::Add(type Bitmap::FromFile("C:\\temp\\MyLargebmp.bmp"))

			*>Assign the ImageList objects to the ListView.
			set listView1::LargeImageList to imageListLarge
			set listView1::SmallImageList to imageListSmall

			
           goback.
       end method.
       
       method-id button1_Click final private.
       procedure division using by value sender as object e as type System.EventArgs.
           set listView1::View to type View::LargeIcon
       end method.
      
       end class.