Tips_gui   >   Complexgrids   >   Complex Grids (All Contents)

Complex Grids

Omnis Studio used the term complex grids for a reason. They are powerful, but they are complex.

This section covers tips and demos relating to complex grids.

Click Run Demo in the StudioTips Browser to review complex grid notation in a demo window.

Complex Grid $clearexceptions

The $clearexceptions method had always confused me. I thought it would revert the complex grid to look the way it was before I applied any exceptions.

But, it appears that the logic for $clearexceptions is to revert to the last column setting.

Click the Run Demo button in the StudioTips Browser for a demo.

Complex Grid $ctarget

The row number is not required when setting $ctarget. The target will be on the current line in the data list represented by the complex grid.

Do $ctarget.$assign($cinst.$objs.ComplexGrid.$objs.FieldName)
Do $ctarget.$firstsel.$assign(0)
Do $ctarget.$lastsel.$assign(10000)

Click the Run Demo button in the StudioTips Browser for a demo.

Complex Grid $fieldstyle

I spent a few hours trying to make use of the $fieldstyle property in complex grids only to reach the conclusion that it can't be done. Well, it can't be done for individual cells.

You can change the $fieldstyle for a complex grid column, but you can't change it for a single cell in a column.

Tech Support confirmed this and said that this feature won't be changed.

To work around this problem, you need to relax the #STYLE restrictions on the $fieldstyle properties that you want to be able to change for individual cells in your complex grid. You can then modify the individual properties, instead of trying to change the $fieldstyle.

Click the Run Demo button in the StudioTips Browser for a demo.

Complex Grid $gridcolumn

If you have a reference to an object in a complex grid, how do you know which column of the complex grid it is located in?

The $gridcolumn property will tell you the answer.

; The following code is used in the demo included with this tip.

Switch $cobj.$gridsection
   Case kGridColumnHeader
      OK message (Icon) {The current object is in the "grid column header".////The current object $gridcolumn is: [$cobj.$gridcolumn]}
   Case kGridHeader
      OK message (Icon) {The current object is in the "grid header".////The current object $gridcolumn is: [$cobj.$gridcolumn]}
   Case kGridNone
      OK message (Icon) {The current object is in not in the grid.////The current object $gridcolumn is: [$cobj.$gridcolumn]}
   Case kGridOther
      OK message (Icon) {The current object is in "grid other".////The current object $gridcolumn is: [$cobj.$gridcolumn]}
   Case kGridRow
      OK message (Icon) {The current object is in a "grid row".////The current object $gridcolumn is: [$cobj.$gridcolumn]}
   Default
      OK message (Icon) {The current object does not have a "$gridsection" property.}
End Switch

; NOTE: If you wanted to test whether or not the $cobj is in a complex grid, you could add
; the following "If" statement.

If $cobj.$container().$objtype=kComplexGrid
   ; OK the current object is in a complex grid.
End If

Click the Run Demo button in the StudioTips Browser for a demo.

Complex Grid $gridsection

If you have a reference to an object in a complex grid, how do you know which section of the
complex grid it is located in?

The $gridsection property will tell you the answer.

$gridsection returns the following constants: kGridColumnHeader, kGridHeader, kGridNone, kGridOther, or kGridRow

; The following code is used in the demo included with this tip.

Switch $cobj.$gridsection
   Case kGridColumnHeader
      OK message (Icon) {The current object is in the "grid column header".}
   Case kGridHeader
      OK message (Icon) {The current object is in the "grid header".}
   Case kGridNone
      OK message (Icon) {The current object is in not in the grid.}
   Case kGridOther
      OK message (Icon) {The current object is in "grid other".}
   Case kGridRow
      OK message (Icon) {The current object is in a "grid row".}
   Default
      OK message (Icon) {The current object does not have a "$gridsection" property.}
End Switch

; NOTE: If you wanted to test whether or not the $cobj is in a complex grid, you could add
; the following "If" statement.

If $cobj.$container().$objtype=kComplexGrid
   ; OK the the current object is in a complex grid.
End If

Click the Run Demo button in the StudioTips Browser for a demo.

Complex Grid Columns

To add columns to a complex grid you need to add a divider to the $dividers group.

; Add a divider to the grid object at 'Posn' pixels.
Do irGridObj.$dividers.$add(Posn) Returns rDivider

The following sample code adds a divider 100 pixels after the last divider.

; Make a list of the $dividers group.
Do irGridObj.$dividers.$makelist($ref.$name,$ref.$posn) Returns List

; Sort the list by the $posn property.
Do List.$sort($ref.C2) ;; C2=Column 2

; Get the position of the last divider in the list.
Calculate LastColPosn as List.[List.$linecount].C2

; Add a new divider 100 pixels after the last divider.
Do irGridObj.$dividers.$add(LastColPosn+100) Returns rDivider

Click the Run Demo button in the StudioTips Browser for a demo.

Complex Grid Field $height

You can not change the $height property of a field in an instantiated complex grid using notation. I suspect Omnis Studio ignores this because the $height is limited by the row height.

Complex Grid Field $width

You can not change the $width property of a field in an instantiated complex grid using notation. I suspect Omnis Studio ignores this because the $width could be limited by dividers.

Complex Grid Select lines

If the complex grid $enterable property is set to kTrue, the user can no longer select lines the same way as in a headed list.

This tip shows how to add a $selected checkbox to the complex grid which allows the user to select/unselected lines by checking or unchecking the checkbox.

Set the $dataname property of the checkbox to, iListVar.[iListVar.$line].$selected, where iListVar is the list variable specified in the $dataname property of the complex grid object.

Click the Run Demo button in the StudioTips Browser for a demo.

Complex Grid Spreadsheet UI

Need a clean looking complex grid? Why not make it look like a spreadsheet?

Click the Run Demo button in the StudioTips Browser for a demo.

This demo uses the following code for having the up and down arrow keys move vertically from cell to cell in the complex grid.

; Method: $control - of the complex grid object.

On evKey

; Copy the current entry field contents to the variable.
Calculate [$cobj.$dataname] as $cobj.$contents

Switch pSystemKey
   Case kUp
      
      ; Make sure we aren't on the first line of the list.
      If iList.$line>1
         
         ; Discard the event.
         Process event and continue (Discard event)
         
         ; Change the current line number.
         Do iList.$line.$assign(iList.$line-1)
         
         Redraw {the window. (Could just redraw the grid.)}
         Do $cinst.$redraw()
         
         ; Set the current target.
         Do $ctarget.$assign([$cobj().$fullname])
         
         ; Select the contents of the current target.
         Do $ctarget.$firstsel.$assign(0)
         Do $ctarget.$lastsel.$assign(len($ctarget.$contents))
      End If
      
   Case kDown
      
      ; Make sure we aren't on the last line of the list.
      If iList.$line<iList.$linecount
         Process event and continue (Discard event)
         Do iList.$line.$assign(iList.$line+1)
         Do $cinst.$redraw()
         Do $ctarget.$assign([$cobj().$fullname])
         Do $ctarget.$firstsel.$assign(0)
         Do $ctarget.$lastsel.$assign(len($ctarget.$contents))
      End If
      
End Switch