Guidance
指路人
g.yi.org
software / rapidq / examples / GUI / Grid / QStringGrid delete row.bas

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
'From:   "Slavomir Svetlik"   Tue Oct 7, 2003  6:00 pm
' select an entire row of a qstringgrid component (like
'selectrow in a listview) and delete his content by a keypress (e.g.
'canc).

'-------------------

     DIM Form AS QFORM
     DIM Grid AS QSTRINGGRID
     DIM ActualCol AS INTEGER, ActualRow AS INTEGER

' --------------------------------------- Declarations
     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)

' --------------------------------------- Form Description
     WITH Form
      .Width = 400
      .CAPTION = "Row select and row delete example"
      .Center
     END WITH
' --------------------------------------- Grid Description
     WITH Grid
      .PARENT = Form
      .Width = 380
      .left = 5: .top = 5
      .ColCount = 5
      .AddOptions 10 ' goEditing
      .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

' ----------------------- set numbers of rows
     FOR I = 1 TO Grid.RowCount - 1
      Grid.Cell(0, I) = STR$(I)
     NEXT I

' ----------------------- event OnSelectCell
     SUB SelectCell
      IF Row% < 1 THEN EXIT SUB
      ActualCol = Col%: ActualRow = Row%
      Grid.Repaint
     END SUB

' ----------------------- event OnDrawCell
     SUB DrawCell
      IF Row% = 0 THEN EXIT SUB

      IF Row% = ActualRow THEN
' for each cell in actual row
       FOR I = 0 TO Sender.ColCount-1
        IF Col% = I THEN
' Fill range by color
         Sender.FillRect(Rect.Left, Rect.Top, _
          Rect.Right ,Rect.Bottom, RGB(&HFF,&HFF,&H99))
' Repaint text by other color
         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
' Fill range by color
        Sender.FillRect(Rect.Left, Rect.Top, _
         Rect.Right ,Rect.Bottom, RGB(&HFF,&H99,&H66))
' Repaint text by other color
        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 ' Key Delete
       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
掌柜推荐
 
 
¥950.00 ·
 
 
¥760.00 ·
 
 
¥470.00 ·
 
 
¥387.00 ·
 
 
¥1,370.00 ·
 
 
¥490.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2009-07-25 17:30:04