Page 1 of 1

Different ComboBox at Grid

Posted: Sat Mar 18, 2017 12:35 am
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 4345 times
 
GRID_COMBOBOX.rar
Source files
(1.21 KiB) Downloaded 243 times
 
I hope you like it. :P

Re: Different ComboBox at Grid

Posted: Sat Mar 18, 2017 3:39 am
by bpd2000
Thank you Pablo for sharing

Re: Different ComboBox at Grid

Posted: Sat Mar 18, 2017 5:18 am
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 4329 times
diffalign1.jpg
diffalign1.jpg (21.91 KiB) Viewed 4328 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

Re: Different ComboBox at Grid

Posted: Sat Mar 18, 2017 8:53 am
by serge_girard
Thanks for sharing Pablo !

Serge

Different ComboBox at Grid

Posted: Sat Mar 18, 2017 11:09 am
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

Different ComboBox at Grid

Posted: Sat Mar 18, 2017 11:36 am
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 223 times
 
Now is changing from TextBox to Spinner or TextBox for Character (I think in right aligned).

Re: Different ComboBox at Grid

Posted: Sat Mar 18, 2017 12:16 pm
by Rathinagiri
Good. If we can standardize and do it as "DYNAMICCOLUMNCONTROL" according to some conditions that will complete the circle.

Different ComboBox at Grid

Posted: Fri Mar 24, 2017 11:49 pm
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 221 times

Re: Different ComboBox at Grid

Posted: Sat Mar 25, 2017 8:35 am
by serge_girard
Thanks Pablo, great job !
Serge