[Solved] Horizontal large table inside a dialog
-
- Posts: 10
- Joined: Mon Nov 27, 2017 7:47 pm
[Solved] Horizontal large table inside a dialog
Hello,
I would like to display a 2-row table inside of a dialog. These rows shall display data taken from 2 array variables (first row would contain the headers and the second one: the data).
There would be around 100 elements in each row. Of course, it will not fit in a dialog window. Therefore, I would like to have a scroll bar inside of the display field of a dialog box, which will move the content horizontally.
The problem is that I can't find any dialog control element that would be suitable to this purpose. Do you have any ideas on how to do that ?
Thanks
I would like to display a 2-row table inside of a dialog. These rows shall display data taken from 2 array variables (first row would contain the headers and the second one: the data).
There would be around 100 elements in each row. Of course, it will not fit in a dialog window. Therefore, I would like to have a scroll bar inside of the display field of a dialog box, which will move the content horizontally.
The problem is that I can't find any dialog control element that would be suitable to this purpose. Do you have any ideas on how to do that ?
Thanks
Last edited by Hagar Delest on Sun Dec 10, 2017 11:12 pm, edited 1 time in total.
Reason: tagged [Solved].
Reason: tagged [Solved].
LibreOffice 7.0.4.2 (x64), Windows 10
Re: horizontal large table inside a dialog
You have to create such a dialog at runtime.
I don't know from where I got this code, (perhaps from the forum here, you might search for "UnoControlGridModel")
but here it is. It adds 4 columns and automatically spaces them. But you can see that it automatically adds a scrollbar when you resize the most right one with the mouse. Perhaps there is also something like a fixed horizontal size property or a "rowmodel"?
I don't know from where I got this code, (perhaps from the forum here, you might search for "UnoControlGridModel")
but here it is. It adds 4 columns and automatically spaces them. But you can see that it automatically adds a scrollbar when you resize the most right one with the mouse. Perhaps there is also something like a fixed horizontal size property or a "rowmodel"?
Code: Select all
Sub GridOnDialog()
Dim dlg, dlgmodel, gridmodel, columnmodel, col, datamodel, grid, oListener
dlg = CreateUnoDialog(DialogLibraries.Standard.getByName("Dialog1"))
dlgmodel = dlg.getModel()
' create new grid control
gridmodel = dlgmodel.createInstance("com.sun.star.awt.grid.UnoControlGridModel")
with gridmodel
.PositionX = 10
.PositionY = 10
.Width = 150
.Height = 100
.SelectionModel = com.sun.star.view.SelectionType.MULTI
end with
' add columns
columnmodel = gridmodel.ColumnModel
col = columnmodel.createColumn()
col.Title = "Name"
columnmodel.addColumn(col)
col = columnmodel.createColumn()
col.Title = "Value"
columnmodel.addColumn(col)
col = columnmodel.createColumn()
col.Title = "Value2"
columnmodel.addColumn(col)
col.Title = "Value3"
columnmodel.addColumn(col)
' insert grid control to the dialog
dlgmodel.insertByName("grid", gridmodel)
' fill the grid with data
datamodel = gridmodel.GridDataModel
datamodel.addRow("a", Array("foo", 100,20))
datamodel.addRow("b", Array("bar", 200,300,400))
datamodel.addRow("c", Array("hoge", 300))
datamodel.addRow("d", Array("huga", 400))
' adding the listener for selection changed
grid = dlg.getControl("grid")
oListener = createUnoListener("ListenerGrid_","com.sun.star.awt.grid.XGridSelectionListener")
grid.AddSelectionListener(oListener)
dlg.execute()
dlg.dispose()
End Sub
Sub ListenerGrid_selectionChanged(ev)
Dim S As String
Dim i As Integer
Dim rows
s = ""
rows = ev.Source.getSelectedRows()
for i = 0 to ubound(rows) step 1
s = s & CStr(rows(i)) & chr(10)
next
msgbox s
End Sub
Sub ListenerGrid_disposing(ev)
End Sub
Win7 Pro, Lubuntu 15.10, LO 4.4.7, OO 4.1.3
Free Project: LibreOffice Songbook Architect (LOSA)
http://struckkai.blogspot.de/2015/04/li ... itect.html
Free Project: LibreOffice Songbook Architect (LOSA)
http://struckkai.blogspot.de/2015/04/li ... itect.html
Re: Horizontal large table inside a dialog
Here is a more complete code that lets you define also the column widths.
It creates a 1x10 table from an array and adds a button in the default Standard-Dialog.
It creates a 1x10 table from an array and adds a button in the default Standard-Dialog.
Code: Select all
REM ***** BASIC *****
dim oDlg as variant
Sub Dialog_with_Grid
'run Standard Dialog1
oDlg = CreateUnoDialog(DialogLibraries.Standard.getByName("Dialog1"))
'create Grid
oGridModel = oDlg.Model.createInstance("com.sun.star.awt.grid.UnoControlGridModel")
oGridModel.Name = "myGrid"
With oGridModel
.ShowColumnHeader = True
.ShowRowHeader = false
.HScroll = false
rem.VScroll = True
.Sizeable = True
.Step = 0
End with
oColumnModel = createUnoService("com.sun.star.awt.grid.DefaultGridColumnModel")
Titlesarray=array("Title1","Title2","Title3","Title4","Title5","Title6","Title7","Title8","Title9","Title10")
Valuesarray=array("Value1","Value2","Value3","Value4","Value5","Value6","Value7","Value8","Value9","Value10")
' add columns
for i=0 to ubound(Titlesarray)
oColumn = createUnoService("com.sun.star.awt.grid.GridColumn")
oColumn.Title = Titlesarray(i)
oColumn.Resizeable=true
oColumn.ColumnWidth=30
oColumn.Flexibility=false
oColumnModel.addColumn(oColumn)
next
oGridModel.ColumnModel = oColumnModel
' add Rows
oDataModel = createUnoService("com.sun.star.awt.grid.DefaultGridDataModel")
oDataModel.addRow("a", Valuesarray)
oGridModel.GridDataModel = oDataModel
' create Grid-Controlelement
oGridControl = createUnoService("com.sun.star.awt.grid.UnoControlGrid")
oGridControl.setModel(oGridModel) 'das Model zuweisen
' add Grid-Controlelement to Dialog
oDlg.addControl("tab_g1", oGridControl)
' set Position and Size of Grid-Controlelement (try!)
oGridControl.setPosSize(10,10,330,60, com.sun.star.awt.PosSize.POSSIZE)
REM add a button model
oButtonModel = oDlg.model.createInstance("com.sun.star.awt.UnoControlButtonModel")
oButtonModel.Name = "Value_Button"
oButtonModel.Width = 100
oButtonModel.Height = 20
oButtonModel.PositionX = 10
oButtonModel.PositionY = 50
oButtonModel.Label = "Value of selected Column"
oButtonModel.PushButtonType = com.sun.star.awt.PushButtonType.STANDARD
oDlg.model.insertByName("Value_Button", oButtonModel)
oValue_Listener = CreateUnoListener("Value_Listener_","com.sun.star.awt.XActionListener")
oCmdValue = oDlg.getControl("Value_Button")
oCmdValue.AddActionListener(oValue_Listener)
' run Dialog
oDlg.execute()
' remove action listener after
oDlg.getControl("Value_Button").removeActionListener(oValue_Listener)
End Sub
rem---action listener for button
Sub Value_Listener_actionPerformed( oEv As com.sun.star.awt.ActionEvent )
if NOT oDlg.getControl("tab_g1").hasSelectedRows() then 'keine markierte Zeile
msgbox "Please select a Value!"
exit sub
end if
aZeile = oDlg.getControl("tab_g1").model.GridDataModel.getRowData(oDlg.getControl("tab_g1").getCurrentRow)
msgbox aZeile(oDlg.getControl("tab_g1").CurrentColumn)
End Sub
Sub Value_Listener_disposing( oEv As com.sun.star.lang.EventObject)
End Sub
Win7 Pro, Lubuntu 15.10, LO 4.4.7, OO 4.1.3
Free Project: LibreOffice Songbook Architect (LOSA)
http://struckkai.blogspot.de/2015/04/li ... itect.html
Free Project: LibreOffice Songbook Architect (LOSA)
http://struckkai.blogspot.de/2015/04/li ... itect.html
-
- Posts: 10
- Joined: Mon Nov 27, 2017 7:47 pm
Re: Horizontal large table inside a dialog
Musikai,
Thanks a lot for your codes !
I'll try it and leave some feedback later.
Thanks a lot for your codes !
I'll try it and leave some feedback later.
LibreOffice 7.0.4.2 (x64), Windows 10
-
- Posts: 10
- Joined: Mon Nov 27, 2017 7:47 pm
Re: Horizontal large table inside a dialog
I've implemented the code and it works pretty well.
Thanks again!
Thanks again!
LibreOffice 7.0.4.2 (x64), Windows 10
-
- Posts: 10
- Joined: Mon Nov 27, 2017 7:47 pm
Re: Horizontal large table inside a dialog
One more question relating to this code.. It worked fine, unitl I launched it on another computer
Do you know how to set oGridControl.setPosSize(10,10,330,60, com.sun.star.awt.PosSize.POSSIZE) coordinates to Map AppFont (ma) units ?
Do you know how to set oGridControl.setPosSize(10,10,330,60, com.sun.star.awt.PosSize.POSSIZE) coordinates to Map AppFont (ma) units ?
LibreOffice 7.0.4.2 (x64), Windows 10
Re: Horizontal large table inside a dialog
AppFont was a new word to me.
After reading this:
https://wiki.openoffice.org/wiki/Docume ... Properties
I understand that the Dialogs created with the Dialog Editor or the Width-Properties of the models use Appfont units.
Possize use pixels as read here:
viewtopic.php?f=45&t=85181
This above link above might have your solution.
But even when I only create Dialogs with the editor they don't always look the same on different Systems (Windows, Linux).
BTW I'm curious for what you use such a table. Although I created the code I don't have a clue for what it's good.
If you find a solution for your problem we are always very thankful if you post it here.
After reading this:
https://wiki.openoffice.org/wiki/Docume ... Properties
I understand that the Dialogs created with the Dialog Editor or the Width-Properties of the models use Appfont units.
Possize use pixels as read here:
viewtopic.php?f=45&t=85181
This above link above might have your solution.
But even when I only create Dialogs with the editor they don't always look the same on different Systems (Windows, Linux).
BTW I'm curious for what you use such a table. Although I created the code I don't have a clue for what it's good.
If you find a solution for your problem we are always very thankful if you post it here.
Win7 Pro, Lubuntu 15.10, LO 4.4.7, OO 4.1.3
Free Project: LibreOffice Songbook Architect (LOSA)
http://struckkai.blogspot.de/2015/04/li ... itect.html
Free Project: LibreOffice Songbook Architect (LOSA)
http://struckkai.blogspot.de/2015/04/li ... itect.html
-
- Posts: 10
- Joined: Mon Nov 27, 2017 7:47 pm
Re: Horizontal large table inside a dialog
Thanks, I'll check this solution and let you know if and how it worked.
Well.. I decided to create a spreadsheet with macros to support managing tools in our company. At the moment we have it in normal spreadsheets, but that's not enough.
After few days with Openoffice Basic I decided to create an independent dialog-based interface, which uses spreadsheets just as a database (in fact, users won't even get access to any part of the spreadsheet, other than a button that starts a dialog). I know - spreadsheets are not databases and I'm doing something that macros are not designed for. But I'm going to finish that project and then I can learn java, write it from zero again and release upgraded version .
The table is used after user reported an operation on tool (and before he confirmed it) to make a summary that will show him in 3 simple lines: 1) what's current content of the database for this tool or set of tools (each tool is described by 20 properties), 2) what's the content of the report he/she has already prepared (each contain around 15 records, but the full list of potential changes has almost 100 elements) and 3) how the database and current tools description will change after the action is confirmed.
Sounds complicated but as far it works fine and it takes less than one minute and around 10 clicks to prepare a complex report for a set of tools.
For this purpose your code works very well, users may see current records for 10-20 or even more different tools and scroll the list left/right, up/down, comparing it with the record they prepared, see what will change and what will stay unchanged.
By the way, I can't stand all these expensive, professional softwares with so many obvious functions missing. The softwares that won't even let you to preview of what you are going to record or which let you to upgrade the dictionary with a name that begins with space.. The costs of problems that occured only because someone has registered an item with comma insted of dot are uncountable.. It took me around 10 minutes to prepare a function that eliminates 95% of potential errors when registering new part number in a dictionary, a function that asks: "hey, it looks like 'item X' that we already have registered is something you're trying to register again. Are you sure?".
I'll keep you informed how it works..
Well.. I decided to create a spreadsheet with macros to support managing tools in our company. At the moment we have it in normal spreadsheets, but that's not enough.
After few days with Openoffice Basic I decided to create an independent dialog-based interface, which uses spreadsheets just as a database (in fact, users won't even get access to any part of the spreadsheet, other than a button that starts a dialog). I know - spreadsheets are not databases and I'm doing something that macros are not designed for. But I'm going to finish that project and then I can learn java, write it from zero again and release upgraded version .
The table is used after user reported an operation on tool (and before he confirmed it) to make a summary that will show him in 3 simple lines: 1) what's current content of the database for this tool or set of tools (each tool is described by 20 properties), 2) what's the content of the report he/she has already prepared (each contain around 15 records, but the full list of potential changes has almost 100 elements) and 3) how the database and current tools description will change after the action is confirmed.
Sounds complicated but as far it works fine and it takes less than one minute and around 10 clicks to prepare a complex report for a set of tools.
For this purpose your code works very well, users may see current records for 10-20 or even more different tools and scroll the list left/right, up/down, comparing it with the record they prepared, see what will change and what will stay unchanged.
By the way, I can't stand all these expensive, professional softwares with so many obvious functions missing. The softwares that won't even let you to preview of what you are going to record or which let you to upgrade the dictionary with a name that begins with space.. The costs of problems that occured only because someone has registered an item with comma insted of dot are uncountable.. It took me around 10 minutes to prepare a function that eliminates 95% of potential errors when registering new part number in a dictionary, a function that asks: "hey, it looks like 'item X' that we already have registered is something you're trying to register again. Are you sure?".
I'll keep you informed how it works..
LibreOffice 7.0.4.2 (x64), Windows 10
Re: Horizontal large table inside a dialog
Hi,
great piece of code. I'm new to programming macros for openoffice. How do I change the font, size for the table produced.
I understand its to do with the FontDescriptor but how I apply this to your code I have no idea
regards
great piece of code. I'm new to programming macros for openoffice. How do I change the font, size for the table produced.
I understand its to do with the FontDescriptor but how I apply this to your code I have no idea
regards
windows 10/openoffice version version 4.1.1
Re: Horizontal large table inside a dialog
Here are the properties of UnoControlGridModel:
https://www.openoffice.org/api/docs/com ... Model.html
Setting colors like this works:
But setting font properties of the grid with
doesn't show. MRI tells that the properties are changed but they don't show in the dialog.
Applying the same to the Button works:
https://www.openoffice.org/api/docs/com ... Model.html
Setting colors like this works:
Code: Select all
oGridModel.TextColor = RGB(255,0,0)
Code: Select all
oGridModel.FontWeight = com.sun.star.awt.FontWeight.BOLD
Applying the same to the Button works:
Code: Select all
oButtonModel.FontWeight = com.sun.star.awt.FontWeight.BOLD
Win7 Pro, Lubuntu 15.10, LO 4.4.7, OO 4.1.3
Free Project: LibreOffice Songbook Architect (LOSA)
http://struckkai.blogspot.de/2015/04/li ... itect.html
Free Project: LibreOffice Songbook Architect (LOSA)
http://struckkai.blogspot.de/2015/04/li ... itect.html
Re: Horizontal large table inside a dialog
Is this a fault? or am I doing it wrong? i've tried
I can change the text colour but thats about it nothing else changes
sorry for my ignorance on the subject. I've assumed that the commands are correct as the macro runs without protest
regards
Code: Select all
'create Grid
oGridModel = oDlg.Model.createInstance("com.sun.star.awt.grid.UnoControlGridModel")
oGridModel.Name = "myGrid"
'oGridModel.FontDescriptor = com.sun.star.awt.FontWeight.BOLD
With oGridModel
.ShowColumnHeader = True
.ShowRowHeader = false
.HScroll = false
rem.VScroll = True
.Sizeable = True
.Step = 0
.TextColor = RGB(255,0,0)
.FontWeight = com.sun.star.awt.FontWeight.BOLD
.FontDescriptor.Name = "Arial"
.FontDescriptor.Weight = "Bold"
.FontDescriptor.Height = 24
.FontDescriptor.CharacterWidth = 24
End with
sorry for my ignorance on the subject. I've assumed that the commands are correct as the macro runs without protest
regards
Last edited by RoryOF on Fri Dec 08, 2017 4:21 pm, edited 1 time in total.
Reason: Added [Code] tags [RoryOF, Moderator]
Reason: Added [Code] tags [RoryOF, Moderator]
windows 10/openoffice version version 4.1.1
Re: Horizontal large table inside a dialog
Some properties of the grid are not implemented internally. You could not change font descriptor related properties on the grid control. These properties are not passed from the model to the internal grid implementation even you specify.
Please, edit this thread's initial post and add "[Solved]" to the subject line if your problem has been solved.
Apache OpenOffice 4-dev on Xubuntu 14.04
Apache OpenOffice 4-dev on Xubuntu 14.04
Re: Horizontal large table inside a dialog
I think I understood that.
If the gridcontrolmodel doesn't have the functionality to change the font. Is there a way to change it externally from say the dialog model
Is that how it works. Even thou if it is I can't get that to work either.
So how do I implement changes to the font. How do I set the font size for the grid.
As I said I can change the text color but not the font size?
Is it possible even.
regards
If the gridcontrolmodel doesn't have the functionality to change the font. Is there a way to change it externally from say the dialog model
Is that how it works. Even thou if it is I can't get that to work either.
So how do I implement changes to the font. How do I set the font size for the grid.
As I said I can change the text color but not the font size?
Is it possible even.
regards
windows 10/openoffice version version 4.1.1
Re: [Solved] Horizontal large table inside a dialog
Greetings!
This code is being very useful, thanks for sharing.
I would like to create a grid with some columns filled with information from a query, but it would be possible in at least one to complete the data manually, after the dialogue is running. I don't know if it is possible, any suggestions?
Thank you in advance.
This code is being very useful, thanks for sharing.
I would like to create a grid with some columns filled with information from a query, but it would be possible in at least one to complete the data manually, after the dialogue is running. I don't know if it is possible, any suggestions?
Thank you in advance.
LO 4.3.4 on Windows 8.1