Resolved WinForms - Listbox list items paired values

Cecil

19+ years progress programming and still learning.
The native behaviour of a MS List box is to allow single list items.

I have found a solution on statckoverflow, but I unsure how to translate the C# into ABL.


 
Last edited:

Cecil

19+ years progress programming and still learning.
Do going from VBA is more is o understand?
Thanks. That sort of helped. Shame there is no C#/VB.NET to ABL converter.
It was still a bit of a rosetta stone excise in converting VB.NET to ABL
 
Last edited:

Cecil

19+ years progress programming and still learning.
If anyone is interested here is my working code.

A snippet of the code see attached for a full example.
Code:
method private void InitializeComponent(  ):

...

        /*  */
        /* lbItems */
        /*  */
        this-object:lbItems:FormattingEnabled = true.
        this-object:lbItems:ItemHeight = 16.
        this-object:lbItems:Location = new System.Drawing.Point(195, 514).
        this-object:lbItems:Name = "lbItems".
        this-object:lbItems:SelectionMode = System.Windows.Forms.SelectionMode:MultiSimple.
        this-object:lbItems:Size = new System.Drawing.Size(108, 68).
        this-object:lbItems:TabIndex = 3.
        this-object:lbItems:SelectedIndexChanged:Subscribe(this-object:lbItems_SelectedIndexChanged).
        
...       
        
end method.

Code:
method private void populateSelectionList(  ):
        
        //define variable list as class "System.Collections.Generic.SortedDictionary<character, character>".
        define variable list as class "System.Collections.Generic.Dictionary<character, character>".
        
        //list = new "System.Collections.Generic.SortedDictionary<character, character>"().
        list = new "System.Collections.Generic.Dictionary<character, character>"().
        
        list:Add("ALL", "All").
        list:Add("item 3", "Item 3").
        list:Add("item 2", "Item 2").
        list:Add("item 1", "Item 1").
    
        lbItems:DataSource = new System.Windows.Forms.BindingSource(list, "") .
        lbItems:ValueMember = "Key".
        lbItems:DisplayMember = "Value".
        
        return.

    end method.

Code:
method private void GetSelectedItems(  ):
        
        define variable iLoop                as integer                                                         no-undo.
        define variable listBoxSelectedItems as class                                                           System.Windows.Forms.ListBox+SelectedObjectCollection.
        define variable selectedItem         as "System.Collections.Generic.KeyValuePair<character, character>" no-undo.
        
        listBoxSelectedItems = lbItems:SelectedItems.
        
        //message lbItems:SelectedItems:Count           view-as alert-box info.
        
        //selectedItem = new "System.Collections.Generic.KeyValuePair"( class1:Item[iLoop] ):
        
        do iLoop = 0 to lbItems:SelectedItems:Count - 1:
            
            selectedItem = cast( listBoxSelectedItems:Item[iLoop], "System.Collections.Generic.KeyValuePair<character, character>"  ).
            
            message
                selectedItem:key skip
                selectedItem:value
                view-as alert-box info.
                
        end.
        
        return.

    end method.
 

Attachments

  • MultiSelectionListBox.zip
    3.2 KB · Views: 4
Top