给你一段源码看看 放一个MSFlexGrid1,TextBox1,Combo1 Private Sub Combo1_KeyPress(KeyAscii As Integer) Dim i As Integer, bSame As Boolean If KeyAscii = vbKeyEscape Then Combo1.Visible = False MSFlexGrid1.SetFocus Exit Sub End If If KeyAscii = vbKeyReturn Then MSFlexGrid1.Text = Combo1.Text Combo1.Visible = False MSFlexGrid1.SetFocus With Combo1 bSame = False For i = 0 To .ListCount If .Text = .List(i) Then bSame = True Next i If Not bSame Then .AddItem .Text End With End If End SubPrivate Sub Combo1_LostFocus() Combo1.Visible = False MSFlexGrid1.SetFocus End SubPrivate Sub Form_Load() Dim i As Integer With MSFlexGrid1 .Cols = 5 .Rows = 5 For i = 0 To 4 .RowHeight(i) = 300 Next i End With For i = 1 To 10 Combo1.AddItem i Next i Label1.Caption = "在第一、二行中,双击左键,会出现一文字框(TextBox)..." & vbCr & _ "而第三、四行,会出现选择类表单(ComboBox)..." & vbCr & _ "输入完毕后按下Enter键,资料即可保留于MSFlexGrid中," & vbCr & _ "而按下Esc键则取消输入..." End SubPrivate Sub MSFlexGrid1_DblClick() Dim c As Integer, r As Integer With MSFlexGrid1 c = .Col: r = .Row If c <= 2 Then Text1.Left = .Left + .ColPos(c) Text1.Top = .Top + .RowPos(r) Text1.Width = .ColWidth(c) Text1.Height = .RowHeight(r) Text1 = .Text Text1.Visible = True Text1.SetFocus Else Combo1.Left = .Left + .ColPos(c) Combo1.Top = .Top + .RowPos(r) Combo1.Width = .ColWidth(c) Combo1.Text = .Text Combo1.Visible = True Combo1.SetFocus End If End With End SubPrivate Sub MSFlexGrid1_KeyPress(KeyAscii As Integer) If KeyAscii = vbKeyReturn Then Call MSFlexGrid1_DblClick End If End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = vbKeyEscape Then Text1.Visible = False MSFlexGrid1.SetFocus Exit Sub End If If KeyAscii = vbKeyReturn Then MSFlexGrid1.Text = Text1.Text Text1.Visible = False MSFlexGrid1.SetFocus End If End SubPrivate Sub Text1_LostFocus() Text1.Visible = False MSFlexGrid1.SetFocus End Sub
To:Richard2001(Richard) 你的意思滚动的时候Text1和Combo1没有在正确的位置显示吧? 如果是的话加入 Private Sub MSFlexGrid1_Scroll() Call MSFlexGrid1_DblClick End Sub
To:every() 全局变量 Dim posX As Long Dim posY As LongPrivate Sub MSFlexGrid1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single) posX = x posY = y End Sub在事件 MSFlexGrid1_DblClick()开头加入两句 If posX < MSFlexGrid1.ColWidth(0) Or posY < MSFlexGrid1.RowHeight(0) Then Exit Sub End If其他判断也一样
To znull(随疯而来) : 还是不行。当滚动条从右向左滚动时,TextBox1和Combo1会出现一半在MSFlexGrid上,一半在Form上的情况。你可以试试。
那么: if textbox1.left 小于 flexgrid.left then textbox1.left = flexgrid.left
放一个MSFlexGrid1,TextBox1,Combo1
Private Sub Combo1_KeyPress(KeyAscii As Integer)
Dim i As Integer, bSame As Boolean
If KeyAscii = vbKeyEscape Then
Combo1.Visible = False
MSFlexGrid1.SetFocus
Exit Sub
End If
If KeyAscii = vbKeyReturn Then
MSFlexGrid1.Text = Combo1.Text
Combo1.Visible = False
MSFlexGrid1.SetFocus
With Combo1
bSame = False
For i = 0 To .ListCount
If .Text = .List(i) Then bSame = True
Next i
If Not bSame Then .AddItem .Text
End With
End If
End SubPrivate Sub Combo1_LostFocus()
Combo1.Visible = False
MSFlexGrid1.SetFocus
End SubPrivate Sub Form_Load()
Dim i As Integer
With MSFlexGrid1
.Cols = 5
.Rows = 5
For i = 0 To 4
.RowHeight(i) = 300
Next i
End With
For i = 1 To 10
Combo1.AddItem i
Next i
Label1.Caption = "在第一、二行中,双击左键,会出现一文字框(TextBox)..." & vbCr & _
"而第三、四行,会出现选择类表单(ComboBox)..." & vbCr & _
"输入完毕后按下Enter键,资料即可保留于MSFlexGrid中," & vbCr & _
"而按下Esc键则取消输入..."
End SubPrivate Sub MSFlexGrid1_DblClick()
Dim c As Integer, r As Integer
With MSFlexGrid1
c = .Col: r = .Row
If c <= 2 Then
Text1.Left = .Left + .ColPos(c)
Text1.Top = .Top + .RowPos(r)
Text1.Width = .ColWidth(c)
Text1.Height = .RowHeight(r)
Text1 = .Text
Text1.Visible = True
Text1.SetFocus
Else
Combo1.Left = .Left + .ColPos(c)
Combo1.Top = .Top + .RowPos(r)
Combo1.Width = .ColWidth(c)
Combo1.Text = .Text
Combo1.Visible = True
Combo1.SetFocus
End If
End With
End SubPrivate Sub MSFlexGrid1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyReturn Then
Call MSFlexGrid1_DblClick
End If
End SubPrivate Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = vbKeyEscape Then
Text1.Visible = False
MSFlexGrid1.SetFocus
Exit Sub
End If
If KeyAscii = vbKeyReturn Then
MSFlexGrid1.Text = Text1.Text
Text1.Visible = False
MSFlexGrid1.SetFocus
End If
End SubPrivate Sub Text1_LostFocus()
Text1.Visible = False
MSFlexGrid1.SetFocus
End Sub
你这个贴子好我给你加分(我专门开了贴子给你加分进来)
当有滚动条(把列宽拉得很长即可)时,先在单元格(如第4列第3行)上双击让TextBox1或Combo1显示后,再拉动滚动条使刚才的单元格滚动到显示区外,TextBox1和Combo1的显示还是有问题。你可以试试。
Richard2001(Richard)说的是,你看能这样解决.
还有一个问题是:
当我在MSFlexGrid1上0行和0列上双击,这么也是1行,1列呢?
你先到我那贴子你流个言,分就给你加上.
当滚动条向左拉,使最右边的列只能显示一部分时,其上的TextBox1又如何显示?
你的意思滚动的时候Text1和Combo1没有在正确的位置显示吧?
如果是的话加入
Private Sub MSFlexGrid1_Scroll()
Call MSFlexGrid1_DblClick
End Sub
全局变量
Dim posX As Long
Dim posY As LongPrivate Sub MSFlexGrid1_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
posX = x
posY = y
End Sub在事件 MSFlexGrid1_DblClick()开头加入两句
If posX < MSFlexGrid1.ColWidth(0) Or posY < MSFlexGrid1.RowHeight(0) Then
Exit Sub
End If其他判断也一样
还是不行。当滚动条从右向左滚动时,TextBox1和Combo1会出现一半在MSFlexGrid上,一半在Form上的情况。你可以试试。
if textbox1.left 小于 flexgrid.left then textbox1.left = flexgrid.left