Page 1 of 1
Saving Grid information in Windows
Posted: Wed Apr 19, 2023 3:05 am
by atostaine
I let users move columns and adjust width, sort position, etc. When they close the application, it saves information to a table about column display position, width, etc. to a table.
When they open it again I want to read the table and reset the grid.How can I change the columns info if the column name is in my table? I don't think I can do this.
in this example #columnname would contain 'GRIDCOLUMN14'
Select (#columnName #disppos) from(gridsave)
#columnname.displayposition := #dispPos
endSelect
I think I'll just have to do a case of_field and hardcode all of the columns.
Re: Saving Grid information in Windows
Posted: Wed Apr 19, 2023 9:09 am
by Dino
Hi Art,
Something like this?
Code: Select all
Begin_Com Role(*EXTENDS #PRIM_WEB) Theme(#SYS_THEME<MaterialDesignBlue>)
Define_Com Class(#PRIM_LIST) Name(#List) ColumnHeaderHeight(48) ColumnLines(False) DisplayPosition(1) Height(413) Left(20) Parent(#COM_OWNER) RowHeight(48) TabPosition(1) Top(20) Width(882)
Define_Com Class(#PRIM_LIST.String) Name(#ListColumn1) ColumnWidth(133) DisplayPosition(1) Parent(#List) SortOnClick(True) Source(#EMPNO)
Define_Com Class(#PRIM_LIST.String) Name(#ListColumn2) ColumnWidth(159) DisplayPosition(2) Parent(#List) SortOnClick(True) Source(#SURNAME)
Define_Com Class(#PRIM_LIST.String) Name(#ListColumn3) ColumnWidth(175) DisplayPosition(3) Parent(#List) SortOnClick(True) Source(#GIVENAME)
Define_Com Class(#PRIM_MD.RaisedButton) Name(#Button) Caption('SAVE') DisplayPosition(2) Left(20) Parent(#COM_OWNER) TabPosition(2) ThemeDrawStyle('MediumSuccess') Top(450)
Define_Com Class(#PRIM_MD.RaisedButton) Name(#Button1) Caption('RESTORE') DisplayPosition(3) Left(293) Parent(#COM_OWNER) TabPosition(3) ThemeDrawStyle('MediumError') Top(448)
Def_List Name(#savedvalues) Fields(#STD_STRNG #STD_NUM) Type(*WORKING) Entrys(*MAX)
Evtroutine Handling(#Com_owner.Initialize)
#EMPNO #SURNAME #GIVENAME := "XYZ"
Inz_List Num_Entrys(10)
Endroutine
Evtroutine Handling(#Button.Click)
For Each(#Column) In(#List.Columns)
#STD_STRNG := #Column.Name
#STD_NUM := #Column.ColumnWidth
Add_Entry To_List(#savedvalues)
Endfor
Endroutine
Evtroutine Handling(#Button1.Click)
For Each(#Column) In(#List.Columns)
Loc_Entry In_List(#savedvalues) Where(#STD_STRNG = #Column.Name)
If_Status Is(*OKAY)
#Column.ColumnWidth := #STD_NUM
Endif
Endfor
Endroutine
End_Com
you could also access the columns using their position in the list like this:
Code: Select all
#STD_NUM := #List.Columns<1>.ColumnWidth
but probably using the column.name instead of their position is more maintainable in the long run.
Kind regards
Re: Saving Grid information in Windows
Posted: Sat Apr 22, 2023 5:58 am
by atostaine
I'll have to try this. I knew about FOR *EACH but for some reason it wasn't clicking for me.
Thanks for the reply.
Re: Saving Grid information in Windows
Posted: Tue Apr 25, 2023 12:51 am
by atostaine
Here's the first version of my code that works. Any ideas on how I could move this to the ancestor so I don't have to put this code in every component that has a grid?
I can Define_Pty and get a reference to the grid but I can''t figure out how to pass it to an RP.
Evtroutine Handling(#COM_OWNER.CreateInstance) Options(*NOCLEARMESSAGES *NOCLEARERRORS)
#Sys_Appln.AllowWindowsDragDrop := True
#userId := *user
#formname := #com_owner.Name
#gridName := #grid1.name
Select Fields(#save_name #save_SPos #save_Pos #save_Wid #save_SDir) From_File(gridSaves) With_Key(#userId #formName #gridName)
For Each(#Column) In(#grid1.Columns)
If (#column.Name.UpperCase = #save_name.UpperCase)
#column.width := #save_wid
#column.SortPosition := #save_sPos
#column.SortDirection := #save_sDir
Endif
Endfor
Endselect
Endroutine
Evtroutine Handling(#COM_OWNER.DestroyInstance) Options(*NOCLEARMESSAGES *NOCLEARERRORS)
If (*SSERVER_CONNECTED <> Y)
Return
Endif
#userId := *user
#formname := #com_owner.Name
For Each(#column) In(#Grid1.columns)
#gridName := #grid1.name
#save_name := #column.Name
#save_sPos := #column.SortPosition
#save_Pos := #column.displayPosition
#save_Wid := #column.Width
#save_SDir := #column.SortDirection
Check_For In_File(gridSaves) With_Key(*user #formName #gridName #save_Name) Io_Error(*NEXT)
If_Status Is(*EQUALKEY)
Update Fields(#save_SPos #save_pos #save_wid #save_sDir) In_File(gridSaves) With_Key(*user #formName #gridName #save_Name) Io_Error(*NEXT)
Else
#userId := *user
Insert Fields(#userId #formName #gridName #save_name #save_SPos #save_pos #save_wid #save_sDir) To_File(gridSaves) Io_Error(*NEXT)
Endif
Endfor
Endroutine
Re: Saving Grid information in Windows
Posted: Tue Apr 25, 2023 7:27 am
by Dino
I think you are going to end creating another VLF, meaning, you could create a reusable part that have a grid, with x number columns and from your programs send the values to populate in those columns and to read from them, etc. But you will also have your extra own routines there, like to save and restore position or remembering values, etc.
I dont know how to define this as part of the ancestor, but you can put the code to save and restore in a reusable part like this:
Code: Select all
Function Options(*DIRECT)
* File R418at only have fields STD_TEXTS and STD_STRNG as keys, then STD_NUM.
Begin_Com Role(*EXTENDS #PRIM_OBJT)
Mthroutine Name(SaveFeatures)
Define_Map For(*INPUT) Class(#STD_TEXTS) Name(#TheGridKey)
Define_Map For(*INPUT) Class(#PRIM_GRID) Name(#TheGrid) Pass(*BY_REFERENCE)
#std_Texts := #TheGridKey
For Each(#Column) In(#TheGrid.Columns)
#STD_STRNG := #Column.Name
#STD_NUM := #Column.Width
Check_For In_File(R418at) With_Key(#TheGridKey #STD_STRNG)
If_Status Is(*EQUALKEY)
Update Fields(#STD_NUM) In_File(R418AT)
Else
Insert Fields(*ALL) To_File(R418at)
Endif
Endfor
Endroutine
Mthroutine Name(RestoreFeatures)
Define_Map For(*INPUT) Class(#STD_TEXTS) Name(#TheGridKey)
Define_Map For(*INPUT) Class(#PRIM_GRID) Name(#TheGrid) Pass(*BY_REFERENCE)
For Each(#Column) In(#TheGrid.Columns)
#STD_STRNG := #Column.Name
Fetch Fields(#STD_NUM) From_File(r418at) With_Key(#TheGridKey #STD_STRNG)
If_Status Is(*OKAY)
#Column.Width := #STD_NUM
Endif
Endfor
Endroutine
End_Com
and in your forms, just add that reusable part
Code: Select all
Define_Com Class(#test418rp) Name(#test418rp)
and a couple lines for the create and destroy instance like these:
Code: Select all
Evtroutine Handling(#COM_OWNER.CreateInstance)
#test418rp.RestoreFeatures TheGridKey(#COM_OWNER.Name + "_" + #List.Name) TheGrid(#List)
Endroutine
Evtroutine Handling(#COM_OWNER.DestroyInstance)
#test418rp.SaveFeatures TheGridKey(#COM_OWNER.Name + "_" + #List.Name) TheGrid(#List)
Endroutine
Re: Saving Grid information in Windows
Posted: Wed Apr 26, 2023 12:44 am
by atostaine
Thanks Dino. I guess I've never used Define_map with Pass(*by_reference)