DIM Form AS QFORM
DIM Grid AS QSTRINGGRID
DIM ActualCol AS INTEGER, ActualRow AS INTEGER
DECLARE SUB SelectCell (Col%, Row%, CanSelect%)
DECLARE SUB DrawCell (Col%, Row%, State%, Rect AS QRECT, Sender AS _
QSTRINGGRID)
DECLARE SUB KeyDown (Key AS WORD, Shift AS INTEGER)
WITH Form
.Width = 400
.CAPTION = "Row select and row delete example"
.Center
END WITH
WITH Grid
.PARENT = Form
.Width = 380
.left = 5: .top = 5
.ColCount = 5
.AddOptions 10
.DefaultRowHeight = 15
.Cell(1,1) = "Hello!": .Cell(2,1) = "Press Del"
.Cell(3,1) = "on this": .Cell(4,1) = "line"
.Cell(1,2) = "Press": .Cell(2,2) = "Del"
.Cell(3,2) = "on this": .Cell(4,2) = "line too"
.ColWidths(0) = 30
.OnSelectCell = SelectCell
.OnDrawCell = DrawCell
.OnKeyDown = KeyDown
END WITH
FOR I = 1 TO Grid.RowCount - 1
Grid.Cell(0, I) = STR$(I)
NEXT I
SUB SelectCell
IF Row% < 1 THEN EXIT SUB
ActualCol = Col%: ActualRow = Row%
Grid.Repaint
END SUB
SUB DrawCell
IF Row% = 0 THEN EXIT SUB
IF Row% = ActualRow THEN
FOR I = 0 TO Sender.ColCount-1
IF Col% = I THEN
Sender.FillRect(Rect.Left, Rect.Top, _
Rect.Right ,Rect.Bottom, RGB(&HFF,&HFF,&H99))
Sender.TextOut (Rect.Left+2, _
Rect.Top+2, Sender.Cell(I,_
ActualRow), RGB(&H00,&H00,&HCC), RGB(&HFF,&HFF,&H99))
END IF
NEXT
IF Row% = ActualRow AND Col% = ActualCol THEN
Sender.FillRect(Rect.Left, Rect.Top, _
Rect.Right ,Rect.Bottom, RGB(&HFF,&H99,&H66))
Sender.TextOut (Rect.Left+2, _
Rect.Top+2, Sender.Cell(ActualCol,_
ActualRow), RGB(&H99,&H00,&H00), -1)
END IF
END IF
END SUB
SUB KeyDown
SELECT CASE Key
CASE 46
IF MESSAGEDLG("Delete text from this row?", _
3, 1 OR 2, 0) = 7 THEN EXIT SUB
FOR I = 1 TO Grid.ColCount - 1
Grid.Cell(I, Grid.Row) = ""
NEXT I
END SELECT
END SUB
SelectCell(1,1,0)
Form.SHOWMODAL
|
|