完整代码: sub msflexgrid1_keypress(keyascii as integer) text1.text=text1.text+chr(keyascii) text1.selstart=1 text1.move msflexgrid1.cellleft+msflexgrid1.left,msflexgrid1.celltop+msflexgrid1.top,msflexgrid1.cellwidth,msflexgrid1.cellheight text1.visible=true text1.setfocus end sub 然后在msflexgrid1_leavecell1()中 sub msflexgrid1_leavecell1() if text1.visible=false then exit sub end if msflexgrid1.text=text1.text text1.visible=false text1.text="" end sub
Private Sub MSFlexGrid1_Click() Dim c As Integer Dim r As Integer
With MSFlexGrid1 c = .Col r = .Row Text6.Left = MSFlexGrid1.Left + MSFlexGrid1.ColPos(c) Text6.Top = MSFlexGrid1.Top + MSFlexGrid1.RowPos(r) If .Appearance = 1 Then Text6.Left = Text6.Left + 2 * Screen.TwipsPerPixelX Text6.Top = Text6.Top + 2 * Screen.TwipsPerPixelY End If Text6.Width = .ColWidth(c) Text6.Height = .RowHeight(r) Text6.Text = .Text End With Text6.Visible = True Text6.SetFocus End Sub 以上程序当点击MsFlexGrid的某一单元格时出现一个文本框。 Private Sub MSFlexGrid1_Scroll() Text6.Visible = False End Sub
加一个textbox named txtEdit在grid的click事件中写:
With txtEdit
.Left = grid.CellLeft + 90
.Top = grid.CellTop + .Height + 60
.Height = grid.CellHeight
.Width = grid.CellWidth
.text = grid.text
.Visible = True
.SetFocus
SendKeys "{Home}+{End}"
End WithLeaveCell事件中写:
grid.text = txtEdit.text
txtEdit.text = ""
txtEdit.Visible = False
sub msflexgrid1_keypress(keyascii as integer)
text1.text=text1.text+chr(keyascii)
text1.selstart=1
text1.move msflexgrid1.cellleft+msflexgrid1.left,msflexgrid1.celltop+msflexgrid1.top,msflexgrid1.cellwidth,msflexgrid1.cellheight
text1.visible=true
text1.setfocus
end sub
然后在msflexgrid1_leavecell1()中
sub msflexgrid1_leavecell1()
if text1.visible=false then
exit sub
end if
msflexgrid1.text=text1.text
text1.visible=false
text1.text=""
end sub
Dim c As Integer
Dim r As Integer
With MSFlexGrid1
c = .Col
r = .Row
Text6.Left = MSFlexGrid1.Left + MSFlexGrid1.ColPos(c)
Text6.Top = MSFlexGrid1.Top + MSFlexGrid1.RowPos(r)
If .Appearance = 1 Then
Text6.Left = Text6.Left + 2 * Screen.TwipsPerPixelX
Text6.Top = Text6.Top + 2 * Screen.TwipsPerPixelY
End If
Text6.Width = .ColWidth(c)
Text6.Height = .RowHeight(r)
Text6.Text = .Text
End With
Text6.Visible = True
Text6.SetFocus
End Sub
以上程序当点击MsFlexGrid的某一单元格时出现一个文本框。
Private Sub MSFlexGrid1_Scroll()
Text6.Visible = False
End Sub