Calc BASIC | How to alter the previously opened dialog to be active ? And is there double click event for grid in dialog?

1.Two dialogs poped up, only the latest one must be active.

Is it possible to alter the previously opened dialog to be active ?

2.If only ‘Budget System - Average Expenses’ is active, I need to double click on grid row number 2 in order to get the content of first cell, ‘Utilities’, to be placed in Calc cell B6.

Is there double click event for grid and sample codes?

3.I have adapted BASIC codes from Base to use in Calc BASIC of 0006.ods.

Library1 > Module1Original > AvgExpenseDialog

In Calc BASIC line 138, oDialogModel.Title = "GridControl Test" does not show in dialog.

What is this line used for ?


***Edited March 3, 2020:

Attached file : 15825140369332625_1.ods for the comment today.***

Hello,

Please keep to single questions. Multiple get buried from others looking for answers.

Also note that you are basing information on an almost 4 year old question (not an answer). This question was actually asked to have the grid available in a form (not possible to my knowledge). This code was strictly a bunch of code doing a variety of tests and not necessarily all productive. There is a lot of digging just to understand the basics of constructing a grid control.

Your questions:

1.Two dialogs poped up, only the latest one must be active.

Is it possible to alter the previously
opened dialog to be active ?

First, if you want the other dialog to be active just click on the header of the dialog. If you did not want to have both opened, close one with code before opening the other. With code set the dialogs as global and end the execution of what is not wanted.

And how is it know which one was previously opened? In this cas you talk of two. What if there were more? What if they were reversed? Need logic to determine what is what.

2.If only ‘Budget System - Average Expenses’ is active, I need to double
click on grid row number 2 in order to
get the content of first cell,
‘Utilities’, to be placed in Calc cell
B6.

Is there double click event for grid
and sample codes?

Here is what is available → com::sun::star::awt::grid Module Reference

There is nothing for a double click. There is a selection listener. Here is a post incorporating that → Libre Office custom Dialog Table

Edit

Attaching a sample. The first dialog (original) has a key handler attached. When a row is selected & Enter key is used the row with first column entry is displayed. This would be used for your entry to the sheet.

The second dialog uses a mouse handler. Found a method for double click. So a double click on a row will display the data.

Sample (Revised mouse double click) ---- DialogsOrig.ods

End Edit

3.I have adapted BASIC codes from Base to use in Calc BASIC of
C:\fakepath\0006.ods.

Library1 > Module1Original >
AvgExpenseDialog

In Calc BASIC line 138,
oDialogModel.Title = “GridControl
Test” does not show in dialog.

What is this line used for ?

As stated in the beginning, this was a lot of testing. oDialogModel was part of the tests. Nothing shows for this as the actual was based upon oDlgModel.

Edit 2020-02-23:

It appears, based on questions elsewhere, you may not have a handle on listeners. Here is another sample. It contains two menu selections (your insertion). The first uses Account code grid. A double mouse click will insert the code into the selected cell on the sheet. The second selection uses the Item grid. Any selection here will enter the item into the selected cell on your sheet. NOTE: If you use a Print or MsgBox in the selectChange function your system will freeze and a reboot is needed (this is my experience).

Sample ------- GridSelection.ods

@lonk,

Tried testing with an event handler and had problems. When I posted my original question if recalled correctly, the events worked. Have tested with some other definitions and none work. Maybe something has broken in LO.

Example post → Grid control on OOo 3.3.0

Also another post of general interest → Tabellen-Grid in Dialogen

@lonk,

Possibly using a key listener may help. Initial test shows com.sun.star.awt.XKeyListener to work.

@lonk,

Have done some further testing with multiple open non-modal dialogs. Although you can bring to the front one or the other, only the last one opened is actually active. Only method I have found to make the inactive dialog active is to end the execution and then execute it again. This then makes the other dialog inactive until this last one has execute ended.

If both are needed simultaneously (or alternately), consider placing two grid controls on one dialog.

Dear @Ratslinger,

placing two grid controls on one dialog

That is the great idea, thank you so much.

@lonk,

Hope you saw my last edit in the answer with a new sample. It completes your request here and with another post you have had.

Dear @Ratslinger,

And thank you so much again for your examples.

Dear @Ratslinger,

Sorry for many comments.

There was an error message from running Sub PopupGridDialog in Library1 > Module2Modified of GridSelection.ods .

The IDE hilighted at line 162, Globalscope.BasicLibraries.LoadLibrary( "MRILib" ) .

The error message is:

Basic runtime error:

An exception occurred.

Type: com.sun.star.container.NoSuchElementException.

Message:.

Help me please.

@lonk,

Sorry for the inconvenience. Just delete that line. Can also delete the following line containing commented out Mri. This is for an object inspection tool to examine settings and methods.

If you want more information on this tool, see links at the end of my answer here → Elements for GetRegistryKeyContent(“org.openoffice.Setup/Product”)

Dear @Ratslinger,

From this Sub for doubleclick event,

how can the dialog be closed as well within this event of double click?

Sub XMouseHandler_mousePressed(oEvt)
    Dim selectedValue 		As String
    Dim oSheet 				As Object
    Dim oCurrentSelection 	As Object
    Dim aCellAddress
    Dim nColumn 			As Integer
    Dim nRow 				As Integer
    Dim oSelectedCell 		As Object
    If oEvt.ClickCount = 2 Then
        selectedValue 		= gGrid(oEvt.Source.CurrentRow + 1, 1)
        oSheet				= ThisComponent.CurrentController.ActiveSheet
        oCurrentSelection 	= ThisComponent.getCurrentSelection()
        aCellAddress 		= oCurrentSelection.getCellAddress()
        nColumn 			= aCellAddress.Column
        nRow 				= aCellAddress.Row
        oSelectedCell 		= oSheet.getCellByPosition(nColumn, nRow)
        oSelectedCell.setString(selectedValue)
    End If

    'Close the dialog

End Sub

Make oDlg global and before End If:

    oDlg.endExecute()

Dear @Ratslinger,

I have created a new module namely Module2Modified2 with the same code and changed codes in only Sub XMouseHandler_mousePressed(oEvt) in order to show Account name in Calc as well.

Dialog and Grid of Module2Modified2 is perfect.

But double-click on its grid, why does Sub XMouseHandler_mousePressed(oEvt) of Module2Modified act instead?

The result is correct but behavior is like Sub XMouseHandler_mousePressed(oEvt) of Module2Modified.

Please see attached file in edited question.

@lonk,

Please start asking as new questions as the topic is straying. Original topic was answered now you’ve branched into closing the dialog & Handler behavior. Thank You.

Now the problem is that your handlers have the same name it is using the first one it sees in the Standard library. Change the second to begin with say XMouseHandler2_ and change the appropriate create and sub names. A Bug? Not certain.

Also I understand your wanting to use macros to get your specific tasks done. The problem is you don’t seem to understand what many items do. For example, a global variable is available across code and you have defined and assigned oDlg multiple times. This will cause problems.

Also noted in Module2 mouse handler the assignment of selectedValue is incorrect - the two are reversed. These are just some obvious situations.

Please try to understand why the code you are copying does what it does.