以下是引用shonken在2023-4-29 14:40:36的发言:
我用过ActiveRow ,要GRID取得焦点才会生效,而且只是当前显示的内容才斑马色,滚动后的数据也没效果
有个问题:grid失焦时ActiveRow为0,导致不管当前在那一行MOD(this.ActiveRow,2)都为0。
简单测试了一下,其他好像还可以接受。
程序代码:
DECLARE LONG PostMessage IN User32 LONG, LONG, LONG, LONG
CREATE CURSOR tt (F1 I, F2 C(10))
FOR i = 1 TO 100
INSERT INTO tt VALUES (i%2, PADL(i,4,"0"))
ENDFOR
GO TOP
of = CREATEOBJECT("form1")
of.show(1)
RETURN
DEFINE CLASS form1 As Form
AllowOutput = 0
AutoCenter = 1
ADD OBJECT cmd1 as commandbutton WITH top=4,left=10,height=22,caption="SORT"
ADD OBJECT text1 as textbox WITH top=4,left=120
ADD OBJECT grid1 as myGrid WITH top=30
PROCEDURE Init
BINDEVENT(this.hWnd, 0x401, this, "myGridSetFocus")
PostMessage(thisform.hWnd, 0x401, 0, 0)
ENDPROC
PROCEDURE cmd1.Click
IF DESCENDING()
INDEX on F2 TAG tt_F2 ASCENDING
ELSE
INDEX on F2 TAG tt_F2 DESCENDING
ENDIF
thisform.Grid1.SetFocus
ENDPROC
FUNCTION myGridSetFocus(hWnd, nMsg, wParam, lParam)
this.Grid1.SetFocus
ENDPROC
ENDDEFINE
DEFINE CLASS myGrid as Grid
PROCEDURE init
this.SetAll("DynamicBackColor", "IIF(MOD(this.ActiveRow,2)==0,0xF0F0F0,0xC0C0C0)", "Column")
ENDPROC
PROCEDURE Scrolled(nDirection)
DODEFAULT()
PostMessage(thisform.hWnd, 0x401, 0, 0)
ENDPROC
ENDDEFINE