DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

[Dialog Box] Keeping the index of the items in a listbox

Solved!
Go to solution

Hey guys!

 

I can't seem to figure this out. 

I have designed a dialog box shown in the "Dialog box indexing.png" attachment.

In the Listbox on the left, I have the channels of what the users can choose from.

When a user moves certain channels to the right and clicks plot, they can see the channels plotted in the VIEW panel.

 

The problem I have is when I move the channels back to the left side; the order of the channels gets mixed up.

For example, If I have channels [1-6], the starting view would look like this:

Left Side                 Right side

[1]

[2]

[3]

[4]

[5]

[6]

 

If I want to see the plots of channels 2 and 3,

Left Side                 Right side

[1]                           [2]

[4]                           [3]

[5]

[6]

 

If I want to remove channels [2] and [3], my box becomes

Left Side                 Right side

[1]

 

[4]

[5]

[6]

[2]

[3]

,but I want it to be as it was initially, with the channels in order.

 

I've added the channels by

Call ListBox1.Items.Add("Channel 1", 0)
Call ListBox1.Items.Add("Channel 2", 1)

etc.

into Listbox 1, and moving the channels to Listbox 2 was coded (partial code) as follows

Sub ListBox1_EventDblClick(ByRef This) 'Created Event Handler
Dim i
i = Listbox1.Selection  
  Call ListBox2.Items.Add(Listbox1.Items.Item(i).Text, i)
  Call ListBox1.Items.Remove(i)
End Sub

Anyone have any suggestions on how I could do this?

 

I would be very grateful for all sorts of advice!

 

Thank you all for taking your time in reading this!!

-Tim

 

 

 

0 Kudos
Message 1 of 4
(3,575 Views)

There should be no gap between channels [1] and [4] at the last example. I think this was a typo

0 Kudos
Message 2 of 4
(3,573 Views)
Solution
Accepted by topic author kmyan9

Hi,

Do you need the elements sorted alphabetically?

If yes, you can use the Sort property of the ListBox:

ListBox.PNG

Alternatively you can implement a simple bubble sort algorithm that sorts your ListBox elements each time you add something new.

If you need the old position inside the other ListBox you have to save it somewhere to use it again when you move an element back.

Christian
CLA, CTA, CLED
Message 3 of 4
(3,546 Views)

Hello Christian!

 

I think you already helped me with another issue so thank you again!

 

I just needed the elements to be sorted "somehow", and the alphabetical method works perfectly with my application.

Thank you for the easy and simple solution.

 

I hope you have a good day!

-Tim

0 Kudos
Message 4 of 4
(3,518 Views)