| View previous topic :: View next topic |
| Author |
Message |
jose3 Power User

Joined: 13 Apr 2004 Posts: 53 Location: Buenos Aires - Argentina
|
Posted: Sun Jan 09, 2005 8:45 pm Post subject: Get data from listbox |
|
|
Hi guys:
I have succeded in populating data from a query into a listbox within a form like this:
| Code: |
While ResultFamily.next
Dim Familiares as string
Familiares=ResultFamily.getString(1)
Dim ListBox as Object
ListBox = oDialog.getControl("ListBox1")
ListBox.AddItem(Familiares,0)
CounterListView=CounterListView+1
Wend
|
I cannot take the data out of the listbox in order to bookmark it on the document. The StarOffice 7 manual does not have any similar sample and from all the templates I have downloaded I got confused in using them.
Does anybody has a sample or way how to do this?
Thanks very much in advance. |
|
| Back to top |
|
 |
pitonyak Administrator


Joined: 09 Mar 2004 Posts: 3618 Location: Columbus, Ohio, USA
|
Posted: Sun Jan 09, 2005 9:08 pm Post subject: |
|
|
I find the following statement confusing:
| Quote: | | I cannot take the data out of the listbox in order to bookmark it on the document. |
Do you want to read data from a listbox?
You can use things such as "getSelectedItemPos()" to find the selected item position or "getSelectedItemsPos()" if multiple things are selected. My free document contains few examples of such things (my book contains more). In the free document, search the text for ListBox.
Do you need to know how to create a bookmar? _________________ --
Andrew Pitonyak
http://www.pitonyak.org/oo.php |
|
| Back to top |
|
 |
jose3 Power User

Joined: 13 Apr 2004 Posts: 53 Location: Buenos Aires - Argentina
|
Posted: Sun Jan 09, 2005 9:13 pm Post subject: |
|
|
Thanks for the quik answer pitonyak.
| Quote: |
Do you want to read data from a listbox?
|
Yes I want to take all the data available from a listbox, not just the selected but all of it. That should be for sure made with a For Next maybe.
Thanks again man! |
|
| Back to top |
|
 |
pitonyak Administrator


Joined: 09 Mar 2004 Posts: 3618 Location: Columbus, Ohio, USA
|
Posted: Sun Jan 09, 2005 9:18 pm Post subject: |
|
|
There are complete examples of this in my book, but probably not the free document
You can......
1. Get the model from the control using "getModel()" and then access the "StringItemList" property, which is an array of strings.
2. On the list box itself, call "getItemCount()" to see how many items are there and then call "getItem(i)" to get the items from the list box. _________________ --
Andrew Pitonyak
http://www.pitonyak.org/oo.php |
|
| Back to top |
|
 |
jose3 Power User

Joined: 13 Apr 2004 Posts: 53 Location: Buenos Aires - Argentina
|
Posted: Sun Jan 09, 2005 9:23 pm Post subject: |
|
|
Thanks man!
I give a try at work and tell you how did I do with it.
Cya! |
|
| Back to top |
|
 |
zap General User

Joined: 28 May 2004 Posts: 40
|
Posted: Mon Jan 10, 2005 3:38 am Post subject: |
|
|
the stringItemList is a read/write property, if you collect your database results in an array first and then use, it's much faster.
| Quote: |
function fillListWithQuery (list as object, query as string) as integer
static block as integer
if isNULL (block) then block = 0
if block = 1 then exit function
block = 1
dim items(200) as string
' dim valueitems(200)
result = db.query(query)
' emptyList (list)
i = 0
upper = 200
if not(isNull(result)) then
while result.next
items (i) = result.getString (1)
' valueitems (i) = result.getString (2)
i = i+1
if i > upper then
upper = upper+100
ReDim Preserve items(upper) as string
' ReDim Preserve valueitems(upper)
end if
wend
end if
' adjust to actual bounds
if i > 0 then
ReDim Preserve items(i-1) as string
list.stringItemList = items ()
getView(list).selectItemPos(0, true)
else
emptyList (list)
end if
block = 0
end function
|
|
|
| Back to top |
|
 |
jose3 Power User

Joined: 13 Apr 2004 Posts: 53 Location: Buenos Aires - Argentina
|
Posted: Tue Jan 18, 2005 7:09 pm Post subject: |
|
|
Thanks boys for the answers. pitonyak I followed your tip but thanks all indeed.
I could make the get dat but I am actually stucked trying to put that data into the documents bookmarks.
The idea is to populate all the items in the listview into the documents bookmarks wich are called numerically like this: "Familiar_" & X.
I get an error here.
| Code: |
oBookmark = oDoc.createInstance("com.sun.star.text.Bookmark")
nCount = oDialog.getControl("ListBox1").getItemCount()
FOR X=0 TO NCOUNT-1
ValListRow=oDialog.getControl("ListBox1").getItem(X)
oBookmark.Name = "Familiar_" & X
oDoc.getBookmarks().getByName("Familiar_" & X).getAnchor.setString(ValListRow) '--------------->> here
next
|
It does work when I dont use variables in it.
Am I going the write way??
Thanks very much!!!!  |
|
| Back to top |
|
 |
jose3 Power User

Joined: 13 Apr 2004 Posts: 53 Location: Buenos Aires - Argentina
|
Posted: Wed Jan 19, 2005 3:34 pm Post subject: |
|
|
this wasnt very clear, no?
Please guys tell me if so.
Thanks. |
|
| Back to top |
|
 |
Peter OOo Enthusiast

Joined: 28 May 2004 Posts: 105 Location: Berlin / Germany
|
Posted: Thu Jan 20, 2005 11:13 pm Post subject: |
|
|
Do you want to set a String to a bookmarks anchor, before the bookmark is inserted into the text content?
Peter |
|
| Back to top |
|
 |
jose3 Power User

Joined: 13 Apr 2004 Posts: 53 Location: Buenos Aires - Argentina
|
Posted: Fri Jan 21, 2005 12:51 pm Post subject: |
|
|
I am sorry Peter but I dont get your question. I dont get too much about OOO basic too I just took the sample from StarOffice Suite programmers manual.
How should I have to be doing it, the other way round?
Thansk very much for your answer. |
|
| Back to top |
|
 |
pitonyak Administrator


Joined: 09 Mar 2004 Posts: 3618 Location: Columbus, Ohio, USA
|
Posted: Fri Jan 21, 2005 1:10 pm Post subject: |
|
|
Let me repeate your code with some comments...
| Code: | REM Create a [b]NEW[/b] that is [b]NOT[/b] in the document
oBookmark = oDoc.createInstance("com.sun.star.text.Bookmark")
nCount = oDialog.getControl("ListBox1").getItemCount()
FOR X=0 TO NCOUNT-1
ValListRow=oDialog.getControl("ListBox1").getItem(X)
REM Great, you set the name of the bookmark, but you have
REM still never added the bookmark into the document!
REM So, as soon as you try to get it, things will fail.
REM You need to insert it into the document first!
oBookmark.Name = "Familiar_" & X
oDoc.getBookmarks().getByName("Familiar_" & X).getAnchor.setString(ValListRow) '--------------->> here
next |
_________________ --
Andrew Pitonyak
http://www.pitonyak.org/oo.php |
|
| Back to top |
|
 |
|