ComboBox

Hello, I have a problem I need to fill a ComboBox in various programs, I was thinking about making a routine which would read the file and fills the ComboBox of the program that called this routine is to do this, thank you

  • Verified Answer

    I have attached an example which invokes a method in a class that will create a List object containing the records of a data file and then return that list to the form so that it can be used in binding to a combobox control.

    The source is as follows:

           class-id bindcombo.Form1 is partial
                     inherits type System.Windows.Forms.Form.
           
           working-storage section.
           method-id NEW.
           procedure division.
               invoke self::InitializeComponent
               declare fl as type bindcombo.fillList = new bindcombo.fillList
               set bindingSource1::DataSource to fl::getList
               set comboBox1::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.
           
           method-id comboBox1_SelectionChangeCommitted final private.
           procedure division using by value sender as object e as type System.EventArgs.
               invoke type MessageBox::Show("Selection is " & comboBox1::SelectedItem)
           end method.
          
           end class.
    
           class-id bindcombo.fillList.
               select item-file assign to "itemfile.txt"
                                organization is line sequential
                                file status is file-status.
           file section.
           fd item-file.
           01 item-record  pic x(10).
           
           working-storage section.
           01 file-status  pic x(2) value spaces.
           method-id getList.
           local-storage section.
           procedure division returning mylist as list[string].
           
               open input item-file
               create mylist
           
               perform until exit
                  read item-file
                     at end
                        exit perform
                     not at end
                        write mylist from item-record
                  end-read
               end-perform
               close item-file
               goback.
               
           end method.
           end class.
    
    bindcombo.zip
  • Thank you, Chris and sorry for the delay in responding, my hard drive crashed

  • Good morning, after the full combobox how can I take a process complete message ?, thank you

  • I am not quite sure what you are asking for here. Can you please clarify with more detail?

    Thanks

  • In this routine you passed me I need to be given a message.

    For example invoque type  MessageBox :: Show ("process completed ...").

  •       Sorry that I changed the routine and was

              class-id EncheCombos.Class1.

          working-storage section.

          77  fs pic x(002).

          01  Lnk-Parametros.

              03  Lnk-Fim             pic 9(001).

              03  Lnk-CodCliente      pic 9(005).

              03  Lnk-NomeCliente     pic x(050).

          method-id InstanceMethod.

          local-storage section.

          procedure division.

              declare fl as type bindcombo.fillList = new bindcombo.fillList

              goback.

          end method.

          end class.

          class-id bindcombo.fillList.

              select item-file assign to "itemfile.txt"

                               organization is line sequential

                               file status is file-status.

          file section.

          fd item-file.

          01 item-record  pic x(80).

          working-storage section.

          01 file-status  pic x(2) value spaces.

          method-id getList.

          local-storage section.

          procedure division returning mylist as list[string].

              open input item-file

              create mylist

              perform until exit

                 read item-file

                    at end

                       exit perform

                    not at end

                       write mylist from item-record

                 end-read

              end-perform

              close item-file

              invoke type MessageBox::Show("Processo Concluído")

              goback.

          end method.

          end class.