Hi!

Having tried for hours now, searching on the web, trying and failing, there seem to be only one more thing I didn't try yet: To give up...

What I want to do is to copy all values of the cells in a cell range to a combo box in a dialog. I was thinking about doing it the following way:

1. Get a range of cells using the getCellRangeByPosition() method.

2. Select that range, using createCursorByRange().

3. Use getDataArray() to copy every value to an array in one step.

4. Using addItems to copy the whole array directly to the combo box...


Is this possible? At least I failed, but again, I am only a beginner yet.


My failing code looks something like this (sorry for using Swedish names for some variables and stuff):


Sub addItemsComboBoxKund
        Dim Ctl As Object
        Dim Doc, Sheet, Range, Cursor As Object
        Dim Kunder As Variant
        
        Doc=StarDesktop.CurrentComponent
        Sheet=Doc.Sheets.getByName("Kunder")

        Range=Sheet.getCellRangeByPosition(1,1,1,13) ' B2:B14, right?
        Cursor=Sheet.createCursorByRange(Range)
        Kunder=Cursor.getDataArray()

        Ctl=Dlg.getControl("ComboBoxKund")
        Ctl.addItems(Kunder,0)
End Sub

So now you probably think something like "why on earth did he think that that is actually going to work?". Well, again I am a beginner... ;D

Obviously the problem is at the "Kunder=Cursor.getDataArray()" line. After a lot of searching I found this:

http://api.openoffice.org/docs/common/ref/com/sun/star/sheet/XCellRangeData.html

It says:

"sequence< sequence< any > >
getDataArray();
        
Description
gets an array from the contents of the cell range.
Each element of the result contains a double or a string."


Shouldn't this work? Just for experimenting, I replaced the line "Kunder=Cursor.getDataArray()" with the line "Kunder=Array("a","b","c")" and this worked fine. My combo box now contained "a", "b" and "c", which are three different strings. According to the getDataArray description and to the fact that the selected cells contains strings only, shouldn't that also work?


Of course I could have added one item at a time in a loop, using the addItem instead of the addItems, but I thought adding them all in one move should be a very quick way to do it...

I think I have been looking for the answer almost everywhere now. Why is this? Am I the only one who wants to copy a cell range to a combo box?

Thanks, all you great people out there!
--
Johnny

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to