[Solved] Add/remove data from one ListBox to another

Creating a macro - Writing a Script - Using the API

[Solved] Add/remove data from one ListBox to another

Postby sertvik » Wed Apr 26, 2017 1:31 pm

Hi. Can someone help me out with this one?

What i want for a macro to do:
1) Take data from cells and put it into ListBox1 (done)
2.1) On pressing a button add an entry from ListBox1 to ListBox2 AND do not overwrite it if the next entry is added
2.2) if entry goes from ListBox1 to ListBox2, remove it from ListBox1
2.3) make multi selection to work
3) Use entries from ListBox1 for some anything, for example simply add to a cell or cells

2.1,2.2 and 2.3 are the ones i don't understad how to do. I can't find any info on the internet about ListBox unless its listbox inside the document and not macross type form that i need.
Is there're a simple option to add an entry to ListBox like .InsertData or is there more sophisticated way of doing this?

Code: Select all   Expand viewCollapse view
Dim MyArr() As String
Dim MyArr2() As String
Dim MyString as String
Dim oDialog1 as Object
Dim oSheet

Function CountColumnsRows(Doc,SheetIndex,NumColumns,NumRows)
   Sheet = Doc.Sheets.getByIndex(SheetIndex)
   Curs = Sheet.createCursor
   Curs.gotoEndOfUsedArea(True)
   NumRows = Curs.Rows.Count
   NumColumns = Curs.Columns.Count
End Function

Sub Dialog1Show()    
    DialogLibraries.LoadLibrary("Standard")
    oDialog1 = CreateUnoDialog( DialogLibraries.Standard.Dialog1 )
      oSheet = thisComponent.Sheets(0)
      
   REM Count Rows for first Sheet of this document
   CountColumnsRows(ThisComponent,0,NumColumns,NumRows)
   
      Redim MyArr(NumRows) As String
      Redim MyArr2(NumRows) As String
   row=0
   col=1
   while row <> NumRows
      MyArr(row)=oSheet.getCellByPosition(col,row).String
      row=row+1
   wend

      oDialog1.getControl("ListBox1").getModel().StringItemList = MyArr()

    oDialog1.Execute()
End Sub

Sub Dialog1Box()
   MyArr2(0) = oDialog1.getControl("ListBox1").getSelectedItem()
   oDialog1.getControl("ListBox2").getModel().StringItemList = MyArr2()
End Sub

Sub Dialog1Action()
   oSheet.getCellByPosition(5,5).String = MyArr2(0)
End Sub
Attachments
Untitled 2.ods
(10.9 KiB) Downloaded 36 times
Last edited by sertvik on Thu Apr 27, 2017 11:08 am, edited 2 times in total.
LibreOffice 5.2.6 on Manjaro
sertvik
 
Posts: 14
Joined: Tue Dec 04, 2012 9:11 am

Re: Add/remove data from one ListBox to another

Postby RoryOF » Wed Apr 26, 2017 1:43 pm

A very full set of macros to manipulate Listboxes is distributed with OpenOffice (and probably with LibreOffice - I haven't checked). This can be accessed through /Tools /Macros /Organise macros /OpenOffice BASIC : OpenOffice Macros :Tools :Listbox.
Apache OpenOffice 4.1.4 on Xubuntu 16.04.03 (mostly 64 bit version) and infrequently on Win2K/XP
14 October 2016 was Pooh's 90th birthday
User avatar
RoryOF
Moderator
 
Posts: 25387
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Add/remove data from one ListBox to another

Postby sertvik » Thu Apr 27, 2017 11:04 am

Wow thanks, didn't know about that. Solved my problem even better than i hoped it would.
MoveSelectedListBox(SourceListbox, TargetListbox) - does what it says and works with multiselection. Awesome!
LibreOffice 5.2.6 on Manjaro
sertvik
 
Posts: 14
Joined: Tue Dec 04, 2012 9:11 am


Return to Macros and UNO API

Who is online

Users browsing this forum: No registered users and 5 guests