Highlighted
Absent Member.
Absent Member.
2820 views

Combobox using the ::SelectedIndex method

Jump to solution

My form consists of several dropdown list 'Comboboxes' with several values in each box.

The first time into the code I'm setting up textboxes which accompany these boxes like so...

set mystring to EMPMAIN-USC-RATE(1).

set Tax-USC-R1::SelectedIndex to Tax-USC-R1::FindStringExact(mystring::TrimEnd(' '))

set uscIndex to Tax-USC-R1::SelectedIndex.

>> If Rate 1 is ZERO then disable all entry boxes for USC

if uscIndex = Zero

set TAX-USC-R1-ACO::Enabled to False

set TAX-USC-R1-PCO::Enabled to False

set TAX-USC-R2::Enabled to False

etc etc..

I have 'SelectedIndexChanged' methods attached to each Combobox where I want the user to be taken should they change the initial value thats in the Combobox. The problem is that the code is bouncing to the 'SelectedIndexChanged' method in the initial set up of the boxes which I do not want it to do. Is there a way around this problem?

e.g I only want the 'SelectedIndexChanged'  code to be done IF the user physically changes the value already present and NOT when I set the initial value?

0 Likes
1 Solution

Accepted Solutions
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Combobox using the ::SelectedIndex method

Jump to solution

You can set up a condition flag in working-storage so that you can avoid the first time selectedindex is changed.

Example:

      class-id testcomboselect.Form1 is partial
                inherits type System.Windows.Forms.Form.
      working-storage section.
      01 isInitial   condition-value value true.
      method-id NEW.
      procedure division.
          invoke self::InitializeComponent
          goback.
      end method.
      method-id Form1_Load final private.
      procedure division using by value sender as object e as type System.EventArgs.
          invoke comboBox1::Items::Add("Red")
          invoke comboBox1::Items::Add("Blue")
          invoke comboBox1::Items::Add("Green")
          invoke comboBox1::Items::Add("White")
          set comboBox1::SelectedIndex to 2
      end method.
      method-id comboBox1_SelectedIndexChanged final private.
      procedure division using by value sender as object e as type System.EventArgs.
          if isInitial
             set isInitial to false
          else
             set textBox1::Text to comboBox1::SelectedItem
          end-if
      end method.
      end class.

View solution in original post

0 Likes
3 Replies
Highlighted
Micro Focus Expert
Micro Focus Expert

RE: Combobox using the ::SelectedIndex method

Jump to solution

You can set up a condition flag in working-storage so that you can avoid the first time selectedindex is changed.

Example:

      class-id testcomboselect.Form1 is partial
                inherits type System.Windows.Forms.Form.
      working-storage section.
      01 isInitial   condition-value value true.
      method-id NEW.
      procedure division.
          invoke self::InitializeComponent
          goback.
      end method.
      method-id Form1_Load final private.
      procedure division using by value sender as object e as type System.EventArgs.
          invoke comboBox1::Items::Add("Red")
          invoke comboBox1::Items::Add("Blue")
          invoke comboBox1::Items::Add("Green")
          invoke comboBox1::Items::Add("White")
          set comboBox1::SelectedIndex to 2
      end method.
      method-id comboBox1_SelectedIndexChanged final private.
      procedure division using by value sender as object e as type System.EventArgs.
          if isInitial
             set isInitial to false
          else
             set textBox1::Text to comboBox1::SelectedItem
          end-if
      end method.
      end class.

View solution in original post

0 Likes
Highlighted
Absent Member.
Absent Member.

RE: Combobox using the ::SelectedIndex method

Jump to solution

Ta very much!

0 Likes
Highlighted
Outstanding Contributor.
Outstanding Contributor.

RE: Combobox using the ::SelectedIndex method

Jump to solution

The combobox have limits? I create a combobox with 120 items from a file but at count=65 go out and put just the first 65 items in the combobox.

Tanks

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.