Am 23.11.2024 um 17:26 schrieb Pierre Vacher:
I try to use the SortableGridDataModel <https://www.openoffice.org/api/docs/common/ref/com/sun/star/awt/grid/SortableGridDataModel.html> service with the help of my own XMutableGridDataModel
some time ago I created a basic demo HTH Oliver OPTION EXPLICIT Dim oDialogControl as Object Dim oGridControl as Object Dim oBtnControl as Object Sub GridControlTest() Dim oColumnModel as Object Dim oColumn1 as Object Dim oColumn2 as Object Dim oColumn3 as Object Dim oGridModel as Object Dim oDataModel as Object Dim oDataListener as Object Dim oListener as Object Dim oBtnModel as Object Dim oBtnListener as Object Dim oDialog as Object Dim oDialogModel as Object Dim oWinListener as Object Dim i as Integer oDialogModel = createUnoService("com.sun.star.awt.UnoControlDialogModel") oDialogModel.Title = "GridControl Test" oDialogModel.sizeable = True oDialogControl = createUnoService("com.sun.star.awt.UnoControlDialog") oDialogControl.setModel( oDialogModel ) oDialogControl.setPosSize( 100, 100, 300, 200, com.sun.star.awt.PosSize.POSSIZE) oGridModel = oDialogModel.createInstance("com.sun.star.awt.grid.UnoControlGridModel") oGridModel.Name = "MyGrid" ' oDataModel = createUnoService("com.sun.star.awt.grid.DefaultGridDataModel") oDataModel = oGridModel.GridDataModel For i = 0 To 10 oDataModel.addRow (""&i, Array(Chr(97+i), Chr(65+i), ""&i*10)) Next i oDataListener = CreateUnoListener("XGridData_", "com.sun.star.awt.grid.XGridDataListener") oDataModel.addGridDataListener(oDataListener) ' oColumnModel = createUnoService("com.sun.star.awt.grid.DefaultGridColumnModel") oColumnModel = oGridModel.ColumnModel oColumn1 = createUnoService("com.sun.star.awt.grid.GridColumn") oColumn1.Title = "City" oColumn1.ColumnWidth = 20 oColumn1.MinWidth = 10 oColumn1.MaxWidth = 50 oColumn1.Resizeable = True ' oColumn1.Flexibility = 1 oColumn2 = createUnoService("com.sun.star.awt.grid.GridColumn") oColumn2.Title = "Country" oColumn2.ColumnWidth = 50 oColumn2.MinWidth = 20 oColumn2.MaxWidth = 80 oColumn2.Resizeable = True ' oColumn2.Flexibility = 1 oColumn3 = createUnoService("com.sun.star.awt.grid.GridColumn") oColumn3.Title = "Test" oColumn3.ColumnWidth = 30 oColumn3.MinWidth = 10 oColumn3.MaxWidth = 50 oColumn3.Resizeable = True ' oColumn3.Flexibility = 1 oColumnModel.addColumn(oColumn1) oColumnModel.addColumn(oColumn2) oColumnModel.addColumn(oColumn3) oGridModel.ShowColumnHeader = True oGridModel.ShowRowHeader = True oGridModel.HScroll = True oGridModel.VScroll = True oGridModel.Sizeable = True oDialogModel.insertByName("MyGrid", oGridModel) oGridControl = oDialogControl.getControl("MyGrid") oDialogControl.addControl("MyGrid", oGridControl) oGridControl.setPosSize(10, 10, 280, 140, com.sun.star.awt.PosSize.POSSIZE) oListener = CreateUnoListener("XGridSelection_", "com.sun.star.awt.grid.XGridSelectionListener") oGridControl.addSelectionListener(oListener) oBtnModel = createUnoService("com.sun.star.awt.UnoControlButtonModel") oBtnModel.setPropertyValues( Array("Label", "Name"), Array("Close", "TestBtn")) oBtnControl = createUnoService("com.sun.star.awt.UnoControlButton") oBtnControl.setModel(oBtnModel) oBtnControl.setPosSize(10, 160, 290, 30, com.sun.star.awt.PosSize.POSSIZE) oDialogControl.addControl("MyButton", oBtnControl) oBtnListener = CreateUnoListener("close_", "com.sun.star.awt.XActionListener") oBtnControl.addActionListener(oBtnListener) oWinListener = createUnoListener("win_", "com.sun.star.awt.XWindowListener") oDialogControl.addWindowListener(oWinListener) oDialogControl.setVisible(True) oDialogControl.execute() End Sub Sub win_windowShown(oEvt) End Sub Sub win_windowResized(oEvt) If Not isNull(oEvt) Then If Not isNull(oBtnControl) Then oBtnControl.setPosSize(10, oEvt.Height - 40, oEvt.Width -20, 30, com.sun.star.awt.PosSize.POSSIZE) EndIf If Not isNull(oGridControl) Then oGridControl.setPosSize(10, 10, oEvt.Width -20, oEvt.Height-60, com.sun.star.awt.PosSize.POSSIZE) oGridControl.setVisible(False) Wait(1) oGridControl.setVisible(True) EndIf EndIf End Sub Sub win_windowMoved(oEvt) End Sub Sub win_windowHidden(oEvt) End Sub Sub close_actionPerformed(oEvt) oDialogControl.endExecute() End Sub Sub XGridSelection_selectionChanged(oEvt) Dim oSrc as Object Dim r as Long Dim c as Long Dim sData as String oSrc = oEvt.Source r = oSrc.getCurrentRow c = oSrc.getCurrentColumn sData = oSrc.getModel().GridDataModel.getCellData(c,r) MsgBox(r & "," & c & " - " & sData) oSrc.getModel().GridDataModel.sortByColumn ( c, false ) End Sub Sub XGridSelection_disposing(oEvt) End Sub Sub XGridData_rowsInserted(oEvt) Msgbox "XGridData_rowsInserted" End Sub Sub XGridData_rowsRemoved(oEvt) Msgbox "XGridData_rowsRemoved" End Sub Sub XGridData_dataChanged(oEvt) Msgbox "XGridData_dataChanged" End Sub Sub XGridData_rowHeadingChanged(oEvt) Msgbox "XGridData_rowHeadingChanged" End Sub Sub XGridData_disposing(oEvt) End Sub