|
Reset Column Configuration of a Table Overview: WinDev Tables are flexible and offer what you’d expect from a Table in a MS-Windows program. One can move columns, hide them, resize them and PC Soft’s Table control will even store the most recent column configuration (width, position and state of each table-column) in the registry. Good and bad: if you, the programmer, tick the the check-box ‘store column configuration’ in the Details Tab of the Table control, the user will inevitably be presented with the last column configuration! While this is a big advantage to those wanting to continue their work with a Table it presents a big obstacle to those wanting to use the Table from scratch - as it had been originally designed by the programmer.There’s no easy way to go back to the configuration of columns as originally designed by the programmer! The ‘AAF System menu’ of the Table control doesn’t offer a ‘reset to the original column configuration’ On page 21 of PC Soft’s AAF documentation (WinDev 11 / 2005) it says that users should contact their application provider for restoring the last Table layout to its original state. Though I strongly believe that this should be a *standard menu item* of the AAF system menu, matters didn’t change since 2005 and PC Soft didn’t do anything to add this necessary menu item. OK, so let’s help ourselves and make an addition to the system menu, named ‘Reset Column Configuration’... 1 - Add a Popup Menu. In order to add any menu item/s to the ‘system menu’, you have to add a popup menu to it. The Popup menu will be part of the window, not of the Table control. Add it in the ‘Window Editor’ by clicking Windows .. Popup menu .. Edit. A small window for presenting the Popup menus of the window. Most probably it will be empty. Add a Popup menu. Accept the default name. 2 - Edit the Popup menu and add the menu item ‘Reset Column Configuration’ (or the equivalent in your local language). 3 - Add code to the menu item ‘Reset Column Configuration’ TC, TX, TW, TD are intPopName is string = PopupField()TN is string TC = TableCount(PopName,toColumn) FOR TX = 1 TO TC TN = TableEnumColumn(PopName,TX) TableMoveColumn(PopName,TN,TX) IF {PopName+"."+TN,indControl}..InitialVisible = True THEN {PopName+"."+TN,indControl}..Visible = True {PopName+"."+TN,indControl}..Width = {PopName+"."+TN,indControl}..InitialWidth TW += {PopName+"."+TN,indControl}..Width ENDEND TD = {PopName,indControl}..Width - TW - 18 // 18 ~= Width of vertical scrollbar of TableFOR TX = 1 TO TC TN = TableEnumColumn(PopName,TX) IF {PopName+"."+TN,indControl}..InitialVisible = True THEN {PopName+"."+TN,indControl}..Width += TD * {PopName+"."+TN,indControl}..AnchorRateWidth / 1000 ENDEND Comment: Contrary to most suggested solutions, this one doesn’t look into the registry but it manipulates the Table control on basis of the original column widths (..InitialWidth), the original column order, the original column visibility state (..InitialVisible) and at last expands the width of all columns according to their anchor rate percentage. At design time, make sure that the sum of all the columns anchor rate widths is 100 !! Only thing we do not know is the width of the vertical scrollbar of the Table. This may be different for the WinDev theme you’re using; in the ‘System’ theme the vertical scrollbars of table controls are 18 pixels in width. The procedure is made independent of the Table’s name (the PopName variable carries it), thus you can insert a single PopUpMenu into a window and use it for several Table controls on it. All comments appreciated! Known issue: if one or more columns have been made invisible by the user, the columns will not fill the table control. Solution: Click ‘Reset Columns Column Configuration’ a second time. 4 - Add Popup menu to AAF System Menu of Table control. Open Description window of the table control, choose GUI Tab and add the PopupMenu1 to the System menu. 5 - Example project. Here you can download an example project with 4 resizable Table controls (without any data!) on a single window showing the usage of the system menu’s item ‘Reset Column Configuration’. Please note that Column5 of the tables is designed to stay invisible from start. Download ResetColumnConfiguration.zip
|