Different ComboBox at Grid

Topic Specific Tutorials and Tips.

Moderator: Rathinagiri

Post Reply
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Different ComboBox at Grid

Post by Pablo César »

Hi all,

This is the tip to overcome the limitation of only one Combobox per column and do different inside the Grid with COLUMNCONTROLS:
 
Screen130.png
Screen130.png (24.72 KiB) Viewed 4288 times
 
GRID_COMBOBOX.rar
Source files
(1.21 KiB) Downloaded 239 times
 
I hope you like it. :P
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
bpd2000
Posts: 1207
Joined: Sat Sep 10, 2011 4:07 am
Location: India

Re: Different ComboBox at Grid

Post by bpd2000 »

Thank you Pablo for sharing
BPD
Convert Dream into Reality through HMG
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Different ComboBox at Grid

Post by Rathinagiri »

Really nice trick Pablo. :)

At this juncture I wish to share another trick (which Claudio taught me) to align differently in a column. I am using this trick for a grid to show like a property sheet.

diffalign.jpg
diffalign.jpg (50.81 KiB) Viewed 4272 times
diffalign1.jpg
diffalign1.jpg (21.91 KiB) Viewed 4271 times

Code: Select all

#include "hmg.ch"

Function Main
PRIVATE aRows [20][3]

aRows  [1]  := { 113.12, date(),   '1',  1, .t. }
aRows  [2]  := { 123.12, date(),   '2',  2, .f. }
aRows  [3]  := { 133.12, date(),   '3',  3, .t. }
aRows  [4]  := { 143.12, date(), "A",  4, .f. }
aRows  [5]  := { 153.12, date(),   '2',  5, .t. }
aRows  [6]  := { 163.12, date(),   '3',  6, .f. }
aRows  [7]  := { 173.12, date(), "B",  7, .t. }
aRows  [8]  := { 183.12, date(),   '2',  8, .f. }
aRows  [9]  := { 193.12, date(), "A",  9, .t. }
aRows [10]  := { 113.12, date(),   '1', 10, .f. }
aRows [11]  := { 123.12, date(),   '2', 11, .t. }
aRows [12]  := { 133.12, date(), "C", 12, .f. }
aRows [13]  := { 143.12, date(),   '1', 13, .t. }
aRows [14]  := { 153.12, date(),   '2', 14, .f. }
aRows [15]  := { 163.12, date(),   '3', 15, .t. }
aRows [16]  := { 173.12, date(),   '1', 16, .f. }
aRows [17]  := { 183.12, date(), "B", 17, .t. }
aRows [18]  := { 193.12, date(),   '3', 18, .f. }
aRows [19]  := { 113.12, date(),   '1', 19, .t. }
aRows [20]  := { 123.12, date(),   '2', 20, .f. }

for i := 1 to 20
   if ascan( {'A','B','C'} , aRows[ i, 3 ] ) == 0 
      aRows[ i, 3 ] := rightalignedtext( aRows[ i, 3 ], 120, 'Arial', 9, .f. )
   endif
next i 
DEFINE WINDOW Form_1 ;
    AT 0,0 ;
    WIDTH 600 ;
    HEIGHT 430 ;
    TITLE 'Mixed Data Type Grid Test' ;
    MAIN NOSIZE NOMAXIMIZE

    DEFINE STATUSBAR FONT "Courier New" SIZE 9
        STATUSITEM PadC("Try by clicking at 3rd column and see the ComboBox items",84)
    END STATUSBAR

    @ 10,10 GRID Grid_1 ;
        WIDTH 576 ;
        HEIGHT 330 ;
        HEADERS {'Column 1','Column 2','Column 3','Column 4','Column 5'} ;
        WIDTHS {120,120,120,120,70} ;
        ITEMS aRows ;
        EDIT ;
        JUSTIFY { GRID_JTFY_RIGHT,GRID_JTFY_CENTER,GRID_JTFY_LEFT,GRID_JTFY_RIGHT, GRID_JTFY_LEFT } ;
        COLUMNCONTROLS { {'TEXTBOX','NUMERIC','$ 999,999.99'} , {'DATEPICKER','DROPDOWN'} , {'TEXTBOX'}, { 'SPINNER' , 1 , 20 } , { 'CHECKBOX' , 'Yes' , 'No' } } ;
        COLUMNVALID {{ || .T.},{ || .T.},{ || Valid3()},{ || .T.},{ || .T.}} ;
        CELLNAVIGATION
    
END WINDOW
CENTER WINDOW Form_1
ACTIVATE WINDOW Form_1
Return Nil


Function Valid3()
LOCAL lRet:=.F.
LOCAL c:=This.CellColFocused
LOCAL r:=This.CellRowFocused
LOCAL xValue:=This.CellValue

If !Empty(This.CellValue)
   lRet:=.T.
   If ascan( {'A','B','C'}, xValue ) == 0
      This.CellValue := rightalignedtext( xValue, 120, 'Arial', 9, .f. )
   endif   
Endif
Return lRet

function rightalignedtext( cData, nWidth, cFont, nSize, lBold )
   local hDC, BTstruct
   local nTextSize := 0
   local aTextData := {}
   local nType := BT_TEXT_OPAQUE
   nWidth := nWidth - 15
   hDC := BT_CreateDC ( , BT_HDC_DESKTOP, @BTstruct)
   if lBold
      nType := BT_TEXT_BOLD
   endif
   do while nTextSize < nWidth
      aTextData := BT_DrawTextSize ( hDC, cData, cFont, nSize, nType )
      nTextSize := aTextData[ 1 ]
      if nTextSize < nWidth
         cData := ' ' + cData
      endif
   enddo
   BT_DeleteDC (BTstruct)
   return cData
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Different ComboBox at Grid

Post by serge_girard »

Thanks for sharing Pablo !

Serge
There's nothing you can do that can't be done...
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Different ComboBox at Grid

Post by Pablo César »

Very nice too Rathi !

Amazing results we can get thru BT_DrawTextSize. I loved RightAlignedText function. Thank you for sharing !

Bos Taurus is a real jewel that Claudio has given us. :P
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Different ComboBox at Grid

Post by Pablo César »

As it has done with ComboBox, other controls can be changed on the fly:
 
ColumnControls1.rar
Source files
(1.17 KiB) Downloaded 217 times
 
Now is changing from TextBox to Spinner or TextBox for Character (I think in right aligned).
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
Rathinagiri
Posts: 5471
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

Re: Different ComboBox at Grid

Post by Rathinagiri »

Good. If we can standardize and do it as "DYNAMICCOLUMNCONTROL" according to some conditions that will complete the circle.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
Pablo César
Posts: 4059
Joined: Wed Sep 08, 2010 1:18 pm
Location: Curitiba - Brasil

Different ComboBox at Grid

Post by Pablo César »

Same demo as the previous one but with some differenciated COLUMNWHEN followed of different COLUMNCONTROLS type.
 
ColumnControls4.rar
Source files
(1.22 KiB) Downloaded 214 times
HMGing a better world
"Matter tells space how to curve, space tells matter how to move."
Albert Einstein
User avatar
serge_girard
Posts: 3161
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Contact:

Re: Different ComboBox at Grid

Post by serge_girard »

Thanks Pablo, great job !
Serge
There's nothing you can do that can't be done...
Post Reply