高难度问题,想了两天没想出算法
请高手指点呀
我做了一个带text文本输入的msflexgrid
即可以在grid中的活动行列中输入内容,
其他的控制都做好了,就剩这个没法控制了.

解决方案 »

  1.   

    可能没讲清楚,我的TEXT是随行的row值的变化而move过去的,但scroll事件后当前行已不在grid里面。如何计算text所在的行呢,请高手指点
      

  2.   

    Option ExplicitConst SBS_HORZ = 0
    Const SBS_VERT = 1
    Private Const SIF_RANGE = &H1
    Private Const SIF_PAGE = &H2
    Private Const SIF_POS = &H4
    Private Const SIF_DISABLENOSCROLL = &H8
    Private Const SIF_TRACKPOS = &H10
    Private Const SIF_ALL = (SIF_RANGE Or SIF_PAGE Or SIF_POS Or SIF_TRACKPOS)Private Type SCROLLINFO
        cbSize As Long
        fMask As Long
        nMin As Long
        nMax As Long
        nPage As Long
        nPos As Long
        nTrackPos As Long
    End Type
    Private Declare Function GetScrollInfo Lib "user32" (ByVal hWnd As Long, ByVal n As Long, lpScrollInfo As SCROLLINFO) As LongPrivate Sub MSFlexGrid1_Scroll()
        Dim SInfo As SCROLLINFO
        SInfo.cbSize = LenB(SInfo)
        SInfo.fMask = SIF_ALL
        Call GetScrollInfo(Me.MSFlexGrid1.hWnd, SBS_VERT, SInfo)
        Debug.Print SInfo.nPos
    End Sub
      

  3.   

    你的textbox是在点击网络时定的位吧?
    那么在click事件中取得当时msflexgrid的toprow与row值,row-toprow就是你当前在网格上显示的行数假设为NRow
    scroll事件里再取topr+Nrow,就是滚动后应该显示的行数了
    如:
    dim nRow as integer
    private sub msflexgrid_click()
    nrow=msflexgrid.row-msflexgrid.toprow
    end sub
    private sub msflexgrid_scroll()
      msflexgrid.row=mflexgrid.toprow+nrow
      text1.move msflexgrid.left+msflexgrid.cellleft,msflexgrid.top+msflexgrid.cellTop,
         msflexgrid.cellwidth,msflexgrid.cellheight
    end sub
      

  4.   

    谢谢你给的思路,就是在row值变化的时候记住row值 和toprow值
    我已成功解决