Results 1 to 4 of 4

Thread: Detecting which cell (or row) in a FlexGrid is highlighted

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Ont, Canada, Earth
    Posts
    458
    Hi,
    I'm using a flexgrid control and would like to be able to detect which cell (or which row in the grid) user just clicked on (or selected using keyboard). I want to allow the user to modify the contents of the flexgrid, and since it'a a Read-only control, I need to know which cell was selected.

    Thanks.
    Thanks

    Tomexx.

  2. #2
    Addicted Member Michael Woolsey's Avatar
    Join Date
    Nov 2000
    Location
    Calgary, Alberta, Canada.
    Posts
    243
    I think you are looking for the .Row and .Col properties... When you select a cell these properties should be set to the active cell.

    Hope this helps.
    Michael

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Ont, Canada, Earth
    Posts
    458
    Thanks, I didn't know that.
    Thanks

    Tomexx.

  4. #4
    Junior Member
    Join Date
    Oct 2000
    Posts
    20
    This example requires :
    - CommandButton -> Command1
    - FlexGrid -> msf1
    - TextBox -> txtOverlay

    Dim intX As Integer, intY As Integer
    Dim resizeW As Boolean, resizeH As Boolean
    Dim cWidth As Integer, cHeight As Integer

    Private Sub Command1_Click()
    msf1.Row = 1
    msf1.Col = 1
    msf1.Text = "Test"
    msf1.TextMatrix(5, 4) = "Cel 5,5"
    End Sub

    Private Sub msf1_Click()
    txtOverlay.Width = msf1.CellWidth - 10
    txtOverlay.Height = msf1.CellHeight - 10
    txtOverlay.Left = msf1.Left + msf1.CellLeft + 5
    txtOverlay.Top = msf1.Top + msf1.CellTop + 10
    txtOverlay = msf1.Text
    txtOverlay.SelStart = 0
    txtOverlay.SelLength = Len(txtOverlay)
    txtOverlay.Visible = True
    txtOverlay.SetFocus
    intX = msf1.Col
    intY = msf1.Row
    End Sub

    Private Sub msf1_GotFocus()
    msf1_Click
    End Sub

    Private Sub msf1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
    DoEvents
    msf1_Click
    intX = msf1.Col
    intY = msf1.Row
    cWidth = msf1.CellLeft + msf1.CellWidth - 60
    cHeight = msf1.CellTop + msf1.CellHeight - 60
    If x > cWidth And y > cHeight Then
    resizeW = True
    cWidth = msf1.Left + msf1.CellLeft
    resizeH = True
    cHeight = msf1.Top + msf1.CellTop
    ElseIf x > cWidth Then
    resizeW = True
    cWidth = msf1.Left + msf1.CellLeft
    ElseIf y > cHeight Then
    resizeH = True
    cHeight = msf1.Top + msf1.CellTop
    End If
    End Sub

    Private Sub msf1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    If resizeW = True Then
    msf1.ColWidth(intX) = IIf(x - cWidth + 210 > 25, x - cWidth + 210, 25)
    txtOverlay.Width = msf1.CellWidth - 10
    End If
    If resizeH = True Then
    msf1.RowHeight(intY) = IIf(y - cHeight + 210 > 25, y - cHeight + 210, 25)
    txtOverlay.Height = msf1.CellHeight - 10
    End If
    End Sub

    Private Sub msf1_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
    resizeW = False
    resizeH = False
    End Sub

    Private Sub txtOverlay_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
    Case Is = 13, 40: KeyCode = 0: msf1.TextMatrix(intY, intX) = txtOverlay: txtOverlay = "": msf1.Row = IIf(intY < msf1.Rows - 1, msf1.Row + 1, msf1.Row): msf1_Click:
    Case Is = 37: KeyCode = 0: msf1.TextMatrix(intY, intX) = txtOverlay: txtOverlay = "": msf1.Col = IIf(intX > 1, msf1.Col - 1, msf1.Col): msf1_Click:
    Case Is = 38: KeyCode = 0: msf1.TextMatrix(intY, intX) = txtOverlay: txtOverlay = "": msf1.Row = IIf(intY > 1, msf1.Row - 1, msf1.Row): msf1_Click:
    Case Is = 39: KeyCode = 0: msf1.TextMatrix(intY, intX) = txtOverlay: txtOverlay = "": msf1.Col = IIf(intX < msf1.Cols - 1, msf1.Col + 1, msf1.Col): msf1_Click:
    End Select
    End Sub

    Private Sub txtOverlay_LostFocus()
    msf1.TextMatrix(intY, intX) = txtOverlay
    txtOverlay = ""
    txtOverlay.Visible = False
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width