直接输入是不可以的。不过可以绕过去的。
代码如下
'写入数据到grid控件
Private Sub grid_EnterCell()
Grid.CellBackColor = vbBlue
Grid.CellForeColor = vbWhite
Text1.Text = Grid.Text
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
End Sub
'写入数据到grid控件
Private Sub grid_LeaveCell()
Grid.CellBackColor = vbWhite
Grid.CellForeColor = vbBlue
End Sub
'写入数据到grid控件
Private Sub grid_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Text1.SetFocus
End Sub
'写入数据到grid控件
Private Sub Text1_Change()
Grid.Text = Text1.Text
End Sub
'写入数据到grid控件
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyLeft, vbKeyRight, vbKeyUp, vbKeyDown
KeyCode = 0
End Select
End Sub自己试试吧。

解决方案 »

  1.   

    你可以去http://www.componentone.com/
    下载vsFlexGrid这个空件MSFlexGrid功能强大
      

  2.   

    当然是应该考虑用combobox或者是textbox移动到需要输入的位置,当用户回车的时候使输入的控件显示输入完毕后将输入控件中的内容写到flexgrid中.
    在grid中keydown的事件:
    Private Sub Grid1_KeyDown(KeyCode As Integer, Shift As Integer)
      If KeyCode = 13 Then
        If Len(Text1.Text) <> 14 Then
        Call MsgBox("凭单号输入有误,请检查后重新输入")
        Text1.SetFocus
         Else
          gcol = Grid1.col
          grow = Grid1.row
         Call callcombo
       End If
      End If
    End Sub
    Private Sub callcombo()
       Dim col, row As Integer
       col = Grid1.col
       row = Grid1.row
       If col <> 3 Or row > 5 Then
       Call MsgBox("此项目不能修改 ")
       Else:
       Call fillcombo
       Dim t, w, l As Integer
       t = Grid1.CellTop + Grid1.Top
       w = Grid1.CellWidth
       l = Grid1.CellLeft + Grid1.Left
       Combo1.Top = t
       Combo1.Width = w
       Combo1.Left = l
       Combo1.Visible = True
       Combo1.SetFocus
       End If
    End Sub输入完毕后在combo中回车的事件
    Private Sub Combo1_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 13 ThenCall grid1_leaveCell1
    Dim counter2 As Integer
    Text4.Text = ""
        For counter2 = 1 To 5
        Text4.Text = Val(Text4.Text) + Val(Grid1.TextMatrix(counter2, 2)) * Val(Grid1.TextMatrix(counter2, 3)) / 100
        '在下面有误差
        Next
        Text3.Text = Format((Val(Text4.Text) / (Val(Form1.Label4.Caption) + 1E-24) * 100), "##0")
        Grid1.SetFocus
    End If
    End Sub
    注意还需要调用grid_leavecell和combo的lostfocus的事件,因为如果用户在combo出现的时候用tab将焦点切走的话就很难看了.
    Private Sub Combo1_LostFocus()
       Call Combo1_KeyDown(13, 0)
    End Sub
    Private Sub grid1_leaveCell1()
       Combo1.Visible = False
       Grid1.TextMatrix(grow, 3) = Combo1.Text
    End Sub
      

  3.   

    上面2位说的对,通常都是通过附加的textbox或combobox用代码控制,在发生单元格点击时,自动跑到用户点击的单元格之上(大小,位置都用代码控制)在输入到附加控件后,通过代码写入MsFlexGrid控件!
      

  4.   

    你可以把你的mail给我,我作一个现成的东西给你好了
      

  5.   

    加一个text控件
    Private Sub MSFlexGrid1_Click()
        Text1.Visible = True
        With MSFlexGrid1
            Text1.Left = .Left + .CellLeft
            Text1.Top = .Top + .CellTop
            Text1.Width = .CellWidth
            Text1.Text = .TextMatrix(.Row, .Col)
        End With
    End SubPrivate Sub Form_Click()
        Text1.Visible = False
    End Sub
      

  6.   

    换另外一个控件啊, MSFlexGrid 只是读取数据时很好,像我现在用的 SS32X25就很好,要是要一份可以邮给你的啦,好东东大家一起分享啦!!
      

  7.   

    楼上的是什么SS32X25东东,我也要一个
    [email protected]
      

  8.   

    to :  saiko(小新)
    可以给我一份吗?
    [email protected]