Saving Grid information in Windows

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
atostaine
Posts: 696
Joined: Wed Jan 20, 2016 7:38 am

Saving Grid information in Windows

Post 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.
Art Tostaine
User avatar
Dino
Posts: 477
Joined: Fri Jul 19, 2019 7:49 am
Location: Robbinsville, NC
Contact:

Re: Saving Grid information in Windows

Post 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
atostaine
Posts: 696
Joined: Wed Jan 20, 2016 7:38 am

Re: Saving Grid information in Windows

Post 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.
Art Tostaine
atostaine
Posts: 696
Joined: Wed Jan 20, 2016 7:38 am

Re: Saving Grid information in Windows

Post 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
Art Tostaine
User avatar
Dino
Posts: 477
Joined: Fri Jul 19, 2019 7:49 am
Location: Robbinsville, NC
Contact:

Re: Saving Grid information in Windows

Post 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
atostaine
Posts: 696
Joined: Wed Jan 20, 2016 7:38 am

Re: Saving Grid information in Windows

Post by atostaine »

Thanks Dino. I guess I've never used Define_map with Pass(*by_reference)
Art Tostaine
Post Reply