to:xinshou1979330
差不多解决了,基本上是按照seeze和sky9705的思路写的
aspvbjava把源码都贴出来了,我大致看了一下,大概也就是这些
少了删除部分,不过很简单,用下面的事件就可以了
Private Sub MSHFlexGrid1_KeyDown(KeyCode As Integer, Shift As Integer)
'显示文本框
Sub ShowTextBox()
With MSFlexGrid1
'隐藏文本框,设置高度和宽度
Text1.Visible = False
Text1.Height = .RowHeight(.Row) - (Screen.TwipsPerPixelY) * 2
Text1.Width = .ColWidth(.Col)
' 计算文本框左坐标
Text1.Left = .CellLeft + .Left
Text1.Top = .CellTop + .Top
Text1.Visible = True
Text1.SetFocus
End With
End Sub
Private Sub MSFlexGrid1_KeyPress(KeyAscii As Integer)
Dim char As String
If KeyAscii = 13 Then
Text1.Text = MSFlexGrid1.Text
Text1.SelStart = Len(Text1.Text)
Else
char = Chr$(KeyAscii)
Text1.Text = char
Text1.SelStart = 1
End If
ShowTextBox
KeyAscii = 0
End Sub
'离开网格时,进行处理. 如果第一列有内容,就自动加一行
Private Sub MSFlexGrid1_LeaveCell()
MSFlexGrid1.Text = Text1.Text
If MSFlexGrid1.Col = 0 And MSFlexGrid1.Row <> 0 And MSFlexGrid1.Row = MSFlexGrid1.Rows - 1 And MSFlexGrid1.Text <> "" Then
MSFlexGrid1.Rows = MSFlexGrid1.Rows + 1
End If
End Sub
Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Text1.Visible = False
End Sub
Private Sub MSFlexGrid1_RowColChange()
Text1.Text = MSFlexGrid1.Text
End Sub
Private Sub MSFlexGrid1_DblClick() '双击可以对网格中内容进行编辑
If MSFlexGrid1.Row > 0 And MSFlexGrid1.Col > 0 Then MSFlexGrid1_KeyPress 13
End Sub
'Text1是输入框,起模拟网格的作用,其实输入到文本框后,经过处理送到网格中
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
MSFlexGrid1.Text = Text1.Text
Text1.Visible = False
MSFlexGrid1.SetFocus
'输入完后如果按回车,若不是最后一列,自动到下一列
If MSFlexGrid1.Col < (MSFlexGrid1.Cols - 1) Then
MSFlexGrid1.Col = MSFlexGrid1.Col + 1
'若为最后一列,跳转到下一行的第一列
ElseIf MSFlexGrid1.Row < MSFlexGrid1.Rows - 1 Then
MSFlexGrid1.Row = MSFlexGrid1.Row + 1
MSFlexGrid1.Col = 0
End If
KeyAscii = 0
End If
End Sub
放一个visible=false的textbox
sub MSFlexGrid_click()
with text1
.width=MSFlexGrid.cellwidth
.height=MSFlexGrid.cellheight
.top=MSFlexGrid.top+MSFlexGrid.celltop
.left=MSFlexGrid.left+MSFlexGrid.cellleft
.visible=true
.setfocus
end with
end sub
然后在text1_lostfocus或text1_keypress里传递
MSFlexGrid.textmatrix(MSFlexGrid.row,MSFlexGrid.col)=text1.text
text1.visible=false
大致就是这个思路了