Clipboard from Listbox

Hi,

I want to copy the listbox content into a clipboard.

  [code]Dim i as integer
  Dim s as string
  For i = 0 to Customerslist11.ListCount-1
    s = s + EndOfLine + Customerslist11.cell(i,0)
     if  Customerslist11.Selected(i) then
      //Copy to clipboard
      Dim c as new Clipboard
      c.SetText(s)
      c.Close
    end if
  next[/code]

the result shows selected rows that I want to set into clipboard, but always starting from first row, even I tried to select started from row 3 to row 8.

I am expecting,

3 4 5 6 7 8

but the result is like,

1 2 3 4 5 6 7 8

Thanks
Arief

so don’t copy the entire listbox, copy only what you want

Dim i as integer
      Dim s as string
      For i = 0 to Customerslist11.ListCount-1
         if  Customerslist11.Selected(i) then
         s = s+ Customerslist11.cell(i,0) + EndOfLine 
        end if
      next
          //Copy to clipboard
          Dim c as new Clipboard
          c.SetText(s)
          c.Close

[quote=397074:@Jean-Yves Pochez]Dim i as integer Dim s as string For i = 0 to Customerslist11.ListCount-1 if Customerslist11.Selected(i) then s = s + EndOfLine + Customerslist11.cell(i,0) end if next //Copy to clipboard Dim c as new Clipboard c.SetText(s) c.Close [/quote]
isn’t that what I just say???

you replied 2 seconds before me exactly …

Arief, I think it is important to understand what your code did and what Dave’s do.

You put the code to copy to clipboard inside for - next loop, so it did this:

  • each row add a value to s, check if that row is selected and assign s to clipboard
  • in I = 0, add to s and do not copy to clipboard
  • in I=1, add to s and do not copy to clipboard
  • in I=2, add to s and copy to clipboard
  • in I=3, add to s and copy to clipboard
  • the same until I=7
    so your code always added the row to s and replaced the clipboard 6 times, the first with values 1, 2 and 3, the last with 1 to 8.

What Dave’s code do is:

  • check if row is selected and add to s
  • after for - next copy s to clipboard

Dear Mr. Poo,

Thanks for the details explanation, Mr. S’s code is exactly what I’m looking for,

s = s+ Customerslist11.cell(i,0) + EndOfLine

before its fixed, its always exporting blank row, maybe it happens because Excel array start from 1 not 0 like xojo.listbox.

thanks
Arief