2 rows from one listbox to 1 row in another listbox

How do I add the data in the one column and 2 rows of the first listbox to one column and one row in the other listbox?
If I want it like. Text 1;Text 2

note: it’s not always 2 rows, it could be on or more…

There is not a built-in mechanism that I am aware of. You will have to create a method that manages the ad-hoc logic.

In the case of your 2 rows into one row, let’s say the first listbox has 3 columns. Your method would have 6 properties, possibly named R1c1, R1C2, R1C3 and R2C1, R2C2 and R2C3, that you fill with the data to be moved over to the second listbox. It is then a simple addrow or insertrow to the second listbox, with the appropriate properties in the desired order.

Supposing that you don’t want to add a new row, then it could also be EditCell, where you plug the appropriate property in the cell. Repeat for ach cell that needs an update.

[quote=427220:@Tue Sandbæk]

How do I add the data in the one column and 2 rows of the first listbox to one column and one row in the other listbox?
If I want it like. Text 1;Text 2

note: it’s not always 2 rows, it could be on or more…[/quote]
Here the original post with the image showing. Sorry I can’t help you more.

Is it possible to use some kind of array?

Assuming the upper listbox is Listbox1 and the lower is Listbox2

dim a() as string
dim s as string
dim row as integer

for row = 0 to Listbox2.ListCount-1
   if Listbox2.Selected(row) then a.append Listbox2.Cell(row, 1)
next
s = a.join(";")

Listbox1.Cell(Listbox1.ListIndex, 1) = s

I have not explained me well enough.

The image just shows that when I add the data from the left listbox to the big listbox, I only get the content from the last cell, if I have 2 cell.
What I want is to get both cells from the left listbox into one cell in af new row in the right listbox.
The code I use

[code]SekvensListbox.AddRow
Dim row As Integer
row = SekvensListbox.listCount-1

SekvensListbox.Cell(row, 0) = SkabelonerListbox.Cell(SkabelonerListbox.ListIndex, 0)

For i As Integer = 0 To DataListbox.ListCount-1
SekvensListbox.Cell(row, 1) = DataListbox.Cell(i, 1)
next

SekvensListbox.Cell(row, 2) = LagComboBox.Text
if AutoCheckBox.Value Then
SekvensListbox.Cell(row, 3) = “Auto”
else
SekvensListbox.Cell(row, 3) = “”
end if[/code]

Replace your For/Next loop with something like:

Dim s As String
For i As Integer = 0 To DataListbox.ListCount-1
s  = s + DataListbox.Cell(i, 1) +  “; “
next
SekvensListbox.Cell(row, 1) = s

Untested

The problem is how you read the Row contents before setting it into the second Listbox.

The example above seems to be correct (read Row Cell’s(0) and Row Cell’s(1) and concatenate them into the target Listbox Cell(Row,Cell) where you want to put them.

The Language Reference is your best friend here (apart this forum) :wink:

Thank you jvind, it works!
Just what I needed.

[quote=427313:@jvindSgaardAndersen]Replace your For/Next loop with something like:

Dim s As String
For i As Integer = 0 To DataListbox.ListCount-1
s  = s + DataListbox.Cell(i, 1) +  ; 
next
SekvensListbox.Cell(row, 1) = s

Untested[/quote]