就是这个问题,没有ColChange类似事件,还有MouseDown/MouseMove/MouseUp都在改列宽时无效。天哪,这可怎么办???我放了一个文本,做为编辑器,现在如果用户来调整列宽,那我的那个文本框就不会变,很难看,不知道大家有没有遇到过这个问题,请教了

解决方案 »

  1.   

    我实现的办法就是让行列不能变。否则很难解决这个问题。
    好象以前看到一个贴子,一个据说还是mvp的莫XX竟然说要用timer控件,这不是开玩笑吗?真不知这个mvp是如何当上的。
      

  2.   

    试试这个:
    Option ExplicitPrivate Sub MSHFlexGrid1_Click()
      Call SizeText
      Text1.Visible = True
      Text1.SetFocus
    End SubPrivate Sub MSHFlexGrid1_GotFocus()
      MSHFlexGrid1_RowColChange
    End SubPrivate Sub MSHFlexGrid1_LeaveCell()
      MSHFlexGrid1.Text = Text1.Text
    End SubPrivate Sub MSHFlexGrid1_RowColChange()
      Static OldRow As Integer, OldCol As Integer, Change As Boolean
       
        If Change Then Exit Sub
        Change = True
         
        With MSHFlexGrid1
          If .Col <> OldCol Or .Row <> OldRow Then
            OldRow = .Row
            OldCol = .Col
            
            Call SizeText
            Text1.Visible = True
            Text1.SetFocus
          End If
        End With
      Change = False
    End SubPrivate Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
      With MSHFlexGrid1
        Select Case KeyCode
        
          Case vbKeyRight
            If .Col + 2 > .Cols And .Row + 1 < .Rows Then
              .Col = 1
              .Row = .Row + 1
            ElseIf .Col + 1 < .Cols And .Row < .Rows Then
             .Col = .Col + 1
            End If
          
          Case vbKeyUp
            If .Row - 1 > 0 Then .Row = .Row - 1
          
          Case vbKeyDown, vbKeyReturn
            If .Row + 1 < .Rows Then .Row = .Row + 1
          
          Case vbKeyLeft
            If .Col - 1 = 0 And .Row - 1 <> 0 Then
              .Col = .Cols - 1
              .Row = .Row - 1
            ElseIf .Col - 1 <> 0 Then
              .Col = .Col - 1
            End If
          End Select
        End With
        MSHFlexGrid1_RowColChange
    End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)
      If KeyAscii = vbKeyReturn Then KeyAscii = 0
      If KeyAscii = vbKeyTab Then
        Call Text1_KeyDown(vbKeyRight, 0)
        KeyAscii = 0
      End If
    End SubPrivate Sub Text1_LostFocus()
      Text1.Visible = False
      Call MSHFlexGrid1_RowColChange
    End SubPrivate Sub SizeText()
      With MSHFlexGrid1
        Text1.Text = .Text
        Text1.FontSize = .Font.Size
        Text1.Height = .CellHeight
        
        If .CellLeft + .CellWidth > .Width Then
         Text1.Width = .Width - .CellLeft
        Else
          Text1.Width = .CellWidth
        End If
        
        Text1.Left = .CellLeft + .Left
        Text1.Top = .CellTop + .Top
      End With
    End Sub
      

  3.   

    哈哈,我试了,这是将文本框隐藏的办法,将问题掩盖了。
    Text1.Visible = False 起作用了。
    把这一句去了,就会露出马脚了。
    不过,觉得这样也是可以的,只要文本框失去焦点就让其不可见也是一种解决办法。
      

  4.   

    应该有消息的。查一下MSDN看看。我用Listview的报表式样,也发现这个问题,
    后来弄到一个开源的表格控件,他就有这个事件。交流MSN:[email protected]
      

  5.   

    这里有个 http://www.codeguru.com/vb/controls/vb_othctrl/article.php/c1505/