Listbox, Copy one to another

' Function(s) / Logic...
For lstBoxRow As Integer = 0 To lstBxOrder.ListCount - 1
  For lstBoxCol As Integer = 0 To lstBxOrder.ColumnCount - 1

  Next
  lstBxHeldOrders.AddRow( lstBxOrder.CellValueAt( lstBoxRow, 0 ).ToText
  lstBxHeldOrders.CellValueAt( lstBxHeldOrders.LastRowIndex, 1 ) = lstBxOrder.CellValueAt( 1 ).ToText
  lstBxHeldOrders.CellValueAt( lstBxHeldOrders.LastRowIndex, 2 ) = lstBxOrder.CellValueAt( 2 ).ToText
  lstBxHeldOrders.CellValueAt( lstBxHeldOrders.LastRowIndex, 3 ) = lstBxOrder.CellValueAt( 3 ).ToText
  lstBxHeldOrders.CellValueAt( lstBxHeldOrders.LastRowIndex, 4 ) = lstBxOrder.CellValueAt( 4 ).ToText
  
Next

So I want to move, not copy, data from one ListBox to another. The code above is how I thought I could do this but… I am getting the following error(s):

frmActiveTill.btnSaleHold.MouseDown, line 22 Syntax error
lstBxHeldOrders.AddRow( lstBxOrder.CellValueAt( lstBoxRow, 0 ).ToText

frmActiveTill.btnSaleHold.MouseDown, line 23
There is more than one method with this name but this does not match any of the available signatures.
lstBxHeldOrders.CellValueAt( lstBxHeldOrders.LastRowIndex, 1 ) = lstBxOrder.CellValueAt( 1 ).ToText

First off your inner loop appears to be empty, what are you expecting it to do?

  1. this line:

lstBxHeldOrders.AddRow( lstBxOrder.CellValueAt( lstBoxRow, 0 ).ToText

doesn’t need the .totext and is missing a closing parenthesis.

  1. the remaining lines don’t need the .totext at all, and you’re not specifying a row number in the expressions to the right of the =

A. WHERE IN YOUR CODE DO YOU DELETE THE COPIED ROW ?

b. To be able to achieve your goal, you have to loop backward: from lastRow to firstRow downto 0

That said, from where your data comes (the data used to populate the first listbox) ? :wink:

It’s probably not the right way but this is how I solved the copy problem I was having…

' Function(s) / Logic...
For i As Integer = 0 To lstBxOrder.LastRowIndex
  strBarCode = lstBxOrder.CellValueAt( i, 0 ).ToText
  strProdName =  lstBxOrder.CellValueAt( i, 1 ).ToText
  strQty =  lstBxOrder.CellValueAt( i, 2 ).ToText
  strPrice =  lstBxOrder.CellValueAt( i, 3 ).ToText
  strTax =  lstBxOrder.CellValueAt( i, 4 ).ToText
  
  lstBxHeldOrders.AddRow( strBarCode )
  lstBxHeldOrders.CellValueAt( lstBxHeldOrders.LastRowIndex, 1 ) = strProdName
  lstBxHeldOrders.CellValueAt( lstBxHeldOrders.LastRowIndex, 2 ) = strQty
  lstBxHeldOrders.CellValueAt( lstBxHeldOrders.LastRowIndex, 3 ) = strPrice
  lstBxHeldOrders.CellValueAt( lstBxHeldOrders.LastRowIndex, 4 ) =strTax
  
Next

lstBxOrder.RemoveAllRows ' <-- Emile Schwarz... here is the delete... :D

You don’t need .ToText in your code. CellValueAt returns a string, so in effect, you are converting the string to Text and then converting it back to string when you set the cell value in lstBxHeldOrders.

or just 3 lines

 lstBxHeldOrders.RemoveAllRows

 lstBxHeldOrders.CellValueAt(Listbox.AllRows, Listbox.AllColumns) = lstBxOrder.CellValueAt(Listbox.AllRows, Listbox.AllColumns)

lstBxOrder.RemoveAllRows

I told him he didn’t need .ToText, but for some reason he ignored me.

What you are saying is, the OP should read the CellValueAt documentation page.

actually “everyone should consult the documentation thoroughly before asking questions on here” since there were several answers that would work but were way more code than required :slight_smile:

I almost suggested that, but it is unclear whether he is replacing the contents of lstBoxHeldOrders or appending to it.

Norman - fully agree - but where in the documentation is this code:

From ListBox (deprecated) — Xojo documentation

Sample Code

This example copies all cells from one ListBox into another:

ListBox2.CellValueAt(-1, -1) = ListBox1.CellValueAt(-1, -1)

If you use the IDE and after listbox. press TAB you will see AllRows = -1 and AllColumns = -1 as options. In other words, you can use (-1, -1) or (Listbox.AllRows, Listbox.AllColumns)

Someone should file a bug about the docs :stuck_out_tongue:

Interesting - I didn’t realise that you could iterate through the rows and columns in that way.

Neither did I. But that’s why I said the OP should read the CellValueAt doc page. I’ve not wanted to copy from one listbox to another, so I’ve probably seen that but not registered it.

I’ve got issues with the docs, but there is a lot of info there.