Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Two Questions for QMGRID cell color paint
#1
Hello ~ Gintaras ~!!!

I tried to paint cells on qmgrid but I couldn't although I tried examples as much as I could.

I have 2 questions.


1. In below code, How could I change font color and background color according to row items? (ex all txt to white, rabbit background to red, tiger to blue, horse to green)

 
Code:
Copy      Help
 
Function [b]Function4[/b] [help1][/help1]
[code]\Dialog_Editor

LoadQmGrid

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 300 314 "Dialog" "4"
;3 QM_Grid 0x56031041 0x200 12 12 276 242 "0[]A[]B"
;1 Button 0x54030001 0x4 172 288 48 14 "OK"
;2 Button 0x54030000 0x4 240 288 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040802 "*" "" "" ""

str controls = "3"
str qmg3
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

DlgGrid RN.Init(hDlg 3)
ICsv ADATA._create;ADATA.Separator=","

sel message
,case WM_INITDIALOG goto gInit
,case WM_DESTROY
,case WM_COMMAND goto messages2
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

;gInit
str CSV =
;rabbit,10
;tiger,20
;horse,30
;rabbit,40
ADATA.FromString(CSV)
RN.FromICsv(ADATA)
ret
[/code]



2. I found example which you wrote how to change cell colors when checked, but cell colors were changed when mouseover other cells without check its row's checkbox
till check another checkbox. How could I fix to change row color just when check checkbox of it's row ?

http://www.quickmacros.com/forum/showthr...light=grid
Code:
Copy      Help
Function [b]Function5[/b] [help1][/help1]
[code]\Dialog_Editor
function# hDlg message wParam lParam
if(hDlg) goto messages


;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 223 133 "Dialog"
;3 QM_Grid 0x56031041 0x200 2 0 218 110 "0x33,0,0,0,0x80[]#,,7,[]Name,,7,"
;5 Button 0x54032000 0x0 4 114 100 16 "Get Checked"
;1 Button 0x54030001 0x4 116 114 48 14 "OK"
;2 Button 0x54030000 0x4 170 114 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2030605 "" "" "" ""

str controls = "3"
str qmg3x
if(!ShowDialog("BackgroundColorCheckedRowDlg" &BackgroundColorCheckedRowDlg &controls)) ret


ret
;messages
DlgGrid g.Init(hDlg 3)
sel message
,case WM_INITDIALOG
,_s=
,;1,A
,;2,B
,;3,C
,;4,D
,;5,E
,;6,F
,;7,G
,;8,H
,g.FromCsv(_s ",")
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_NOTIFY goto messages3
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
,case 5 ;;Get Checked
,,ARRAY(int) arrintGetCheckedRows.redim
,,int TotRows = g.RowsCountGet
,,int TotCheckedRows = 0
,,for _i 0 TotRows
,,,if(g.RowIsChecked(_i))
,,,,arrintGetCheckedRows[] = _i
,,,,TotCheckedRows = TotCheckedRows + 1
,,out "Total Checked Rows = %i:" TotCheckedRows
,,for _i 0 arrintGetCheckedRows.len
,,,out arrintGetCheckedRows[_i]

ret 1
;messages3
NMHDR* nh=+lParam
sel nh.idFrom
,case 3
,GRID.QM_NMLVDATA* cd=+nh
,NMLVDISPINFO* di=+nh
,NMLISTVIEW* nlv=+nh
,NMITEMACTIVATE* na=+nh
,NMLVCUSTOMDRAW* cd1=+nh
,int- CheckedRowBit
,sel nh.code
,,;These notifications are from QM_Grid.
,,;All text coming from QM_Grid is in QM format (UTF-8 or ANSI, depending on QM Unicode mode).
,,case [NM_CLICK,NM_DBLCLK,NM_RCLICK] ;;when user clicks a row or empty space, and it does not begin cell edit mode
,,,out "row click: %i %i" na.iItem na.iSubItem
,,case LVN_ITEMCHANGED
,,,int row isChecked
,,,if(g.RowIsCheckNotification(lParam row isChecked)) out "%schecked %i" iif(isChecked "" "un") row
,,,,if(isChecked)
,,,,,CheckedRowBit = 1
,,,,else
,,,,,CheckedRowBit = 0
,,case NM_CUSTOMDRAW
,,,sel cd1.nmcd.dwDrawStage
,,,,case CDDS_PREPAINT ret DT_Ret(hDlg CDRF_NOTIFYITEMDRAW)
,,,,case CDDS_ITEMPREPAINT
,,,,,if(CheckedRowBit)
,,,,,,cd1.clrTextBk = 0xe0ff
,,,,,,g.RowSelect(-1)
,,,,,else
,,,,,,cd1.clrTextBk = 0xFFFFFF
,,,,,,g.RowSelect(-1)
[/code]

Thank you always !!
#2
Quote:1. How could I change font color and background color according to row items? (ex all txt to white, rabbit background to red, tiger to blue, horse to green)
 
Code:
Copy      Help
;LoadQmGrid

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 300 314 "Dialog" "4"
;3 QM_Grid 0x56031041 0x200 12 12 276 242 "0[]A[]B"
;1 Button 0x54030001 0x4 172 288 48 14 "OK"
;2 Button 0x54030000 0x4 240 288 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040802 "*" "" "" ""

str controls = "3"
str qmg3
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

DlgGrid RN.Init(hDlg 3)
ICsv ADATA._create;ADATA.Separator=","

sel message
,case WM_INITDIALOG goto gInit
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_NOTIFY goto messages3
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

;gInit
str CSV =
;rabbit,10
;tiger,20
;horse,30
;rabbit,40
ADATA.FromString(CSV)
RN.FromICsv(ADATA)

ret

;messages3
NMHDR* nh=+lParam
int- row isChecked col
sel nh.idFrom
,case 3
,sel nh.code
,,case NM_CUSTOMDRAW goto gridCustomDraw
,,
;gridCustomDraw
NMCUSTOMDRAW* cd=+lParam
NMLVCUSTOMDRAW* cd2=+lParam
int R ;;the return value
sel cd.dwDrawStage
,case CDDS_PREPAINT
,R=CDRF_NOTIFYITEMDRAW ;;notify to draw items
,case CDDS_ITEMPREPAINT ;;now draw item
,R=CDRF_NEWFONT|CDRF_NOTIFYSUBITEMDRAW ;;notify to draw subitems
,case CDDS_ITEMPREPAINT|CDDS_SUBITEM ;;now draw subitem
,row=cd.dwItemSpec; col=cd2.iSubItem
,str cell=RN.CellGet(row 0)
,sel cell
,,case "rabbit"
,,cd2.clrTextBk=0x0000FF;;; red
,,case "tiger"
,,cd2.clrTextBk=0xFF0000;;;  blue
,,case "horse"
,,cd2.clrTextBk=0x00FF00;;;  green
,cd2.clrText=0xFFFFFF;;; white
ret DT_Ret(hDlg R)
Quote:2. How could I fix to change row color just when check checkbox of it's row ?
 example using your code
Code:
Copy      Help
;LoadQmGrid

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 300 314 "Dialog" "4"
;3 QM_Grid 0x56031041 0x200 12 12 276 242 "0x20,0,0,0x0,0x0[]A,,,[]B,,,"
;1 Button 0x54030001 0x4 172 288 48 14 "OK"
;2 Button 0x54030000 0x4 240 288 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040802 "*" "" "" ""

str controls = "3"
str qmg3x
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

DlgGrid RN.Init(hDlg 3)
ICsv ADATA._create;ADATA.Separator=","

sel message
,case WM_INITDIALOG goto gInit
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_NOTIFY goto messages3
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

;gInit
str CSV =
;rabbit,10
;tiger,20
;horse,30
;rabbit,40
ADATA.FromString(CSV)
RN.FromICsv(ADATA)

ret

;messages3
NMHDR* nh=+lParam
int row isChecked col
sel nh.idFrom
,case 3
,sel nh.code
,,case LVN_ITEMCHANGED
,,if(RN.RowIsCheckNotification(lParam row isChecked)) out "%schecked %i" iif(isChecked "" "un") row
,,case NM_CUSTOMDRAW goto gridCustomDraw

;gridCustomDraw
NMCUSTOMDRAW* cd=+lParam
NMLVCUSTOMDRAW* cd2=+lParam
int R ;;the return value
sel cd.dwDrawStage
,case CDDS_PREPAINT
,R=CDRF_NOTIFYITEMDRAW ;;notify to draw items
,case CDDS_ITEMPREPAINT ;;now draw item
,R=CDRF_NEWFONT|CDRF_NOTIFYSUBITEMDRAW ;;notify to draw subitems
,case CDDS_ITEMPREPAINT|CDDS_SUBITEM ;;now draw subitem
,row=cd.dwItemSpec; col=cd2.iSubItem
,if(RN.RowIsChecked(row))
,,str cell=RN.CellGet(row 0)
,,sel cell
,,,case "rabbit"
,,,cd2.clrTextBk=0x0000FF;;; red
,,,case "tiger"
,,,cd2.clrTextBk=0xFF0000;;;  blue
,,,case "horse"
,,,cd2.clrTextBk=0x00FF00;;;  green
,,cd2.clrText=0xFFFFFF;;; white
ret DT_Ret(hDlg R)
#3
OH~~ Thank you for your reply

Still it seems I need time to understand. anyway, it works

I come again ^^;;;;

How could I change only first cell?

Thanks in advance !
#4
sorry didn't see your last response
 here you go. I have simplified the dialogs some

Function GridColorSpecificCellOnLoad
Code:
Copy      Help
,_s=
,;rabbit,10,100
,;tiger,20,200
,;horse,30,300
,;rabbit,40,400

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 300 168 "Dialog" "4"
;3 QM_Grid 0x56031041 0x200 12 12 276 122 "0x0,0,0,0x4,0x0[]A,,,[]B,,,[]C,,,"
;1 Button 0x54030001 0x4 176 144 48 14 "OK"
;2 Button 0x54030000 0x4 232 144 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040802 "*" "" "" ""

str controls = "3"
str qmg3x =_s
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

DlgGrid grid.Init(hDlg 3)

sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_NOTIFY goto messages3
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

;messages3
NMLVCUSTOMDRAW* cd=+lParam
sel cd.nmcd.dwDrawStage
,case CDDS_PREPAINT _i=CDRF_NOTIFYITEMDRAW ;;yes, notify me to draw items
,case CDDS_ITEMPREPAINT _i=CDRF_NOTIFYSUBITEMDRAW ;;draw subitems
,case CDDS_ITEMPREPAINT|CDDS_SUBITEM
,int row=cd.nmcd.dwItemSpec
,str cell=grid.CellGet(row 0)
,,sel cell
,,,case "rabbit"
,,,if(cd.iSubItem=0) ;;first cell of row rabbit
,,,,cd.clrTextBk=0x0000FF;;; red text background
,,,else
,,,,cd.clrTextBk=0xFFFFFF;;; white text background
,,,case "tiger" 
,,,if(cd.iSubItem=0)    ;; first cell of row tiger
,,,,cd.clrTextBk=0xFF0000;;;  blue text background
,,,,cd.clrText=0xFFFFFF;;; white text
,,,else
,,,,cd.clrTextBk=0xFFFFFF;;; white text background
,,,,cd.clrText=0x000000;;; black text
,,,case "horse"
,,,if(cd.iSubItem=0) ;; first cell of row horse
,,,,cd.clrTextBk=0x00FF00;;;  green text background
,,,else
,,,,cd.clrTextBk=0xFFFFFF;;; white text background            
ret DT_Ret(hDlg _i)


Function GridColorSpecificCellOnCheck
Code:
Copy      Help
,_s=
,;rabbit,10,100
,;tiger,20,200
,;horse,30,300
,;rabbit,40,400

str dd=
;BEGIN DIALOG
;0 "" 0x90C80AC8 0x0 0 0 300 168 "Dialog" "4"
;3 QM_Grid 0x56031041 0x200 12 12 276 122 "0x20,0,0,0x4,0x0[]A,,,[]B,,,[]C,,,"
;1 Button 0x54030001 0x4 176 144 48 14 "OK"
;2 Button 0x54030000 0x4 232 144 48 14 "Cancel"
;END DIALOG
;DIALOG EDITOR: "" 0x2040802 "*" "" "" ""

str controls = "3"
str qmg3x =_s
if(!ShowDialog(dd &sub.DlgProc &controls)) ret


#sub DlgProc
function# hDlg message wParam lParam

DlgGrid grid.Init(hDlg 3)

sel message
,case WM_INITDIALOG
,case WM_DESTROY
,case WM_COMMAND goto messages2
,case WM_NOTIFY goto messages3
ret
;messages2
sel wParam
,case IDOK
,case IDCANCEL
ret 1

;messages3
NMLVCUSTOMDRAW* cd=+lParam
sel cd.nmcd.dwDrawStage
,case CDDS_PREPAINT _i=CDRF_NOTIFYITEMDRAW ;;yes, notify me to draw items
,case CDDS_ITEMPREPAINT _i=CDRF_NOTIFYSUBITEMDRAW ;;draw subitems
,case CDDS_ITEMPREPAINT|CDDS_SUBITEM
,int row=cd.nmcd.dwItemSpec
,if(grid.RowIsChecked(row)) 
,,str cell=grid.CellGet(row 0)
,,sel cell
,,,case "rabbit"
,,,if(cd.iSubItem=0) ;;first cell of row rabbit
,,,,cd.clrTextBk=0x0000FF;;; red text background
,,,else
,,,,cd.clrTextBk=0xFFFFFF;;; white text background
,,,case "tiger" 
,,,if(cd.iSubItem=0)    ;; first cell of row tiger
,,,,cd.clrTextBk=0xFF0000;;;  blue text background
,,,,cd.clrText=0xFFFFFF;;; white text
,,,else
,,,,cd.clrTextBk=0xFFFFFF;;; white text background
,,,,cd.clrText=0x000000;;; black text
,,,case "horse"
,,,if(cd.iSubItem=0) ;; first cell of row horse
,,,,cd.clrTextBk=0x00FF00;;;  green text background
,,,else
,,,,cd.clrTextBk=0xFFFFFF;;; white text background            
ret DT_Ret(hDlg _i)
#5
Thank you, Kevin ~!

I also come by here now ^^*

May God bless you~~
#6
very nice! - if only QmGrid could support multi-line text, with your code samples, I wouldn't need to use msflexgrd at all - mxflxgrid is a hassle to work with, compile, and distribute - all possible, but much easier with qmgrid.
Thanks again!, S


Forum Jump:


Users browsing this thread: 2 Guest(s)