电脑编程技巧 2001。11期 p45页有一篇vb datagrid实现picklist 的功能,我还没来的及看,因为我用delphi(dbgrid有这个功能)。你若是找不到刊物,告诉我,我给你贴。
实现 回车换行,我在delphi 里 实现了,你的后两个功能我没实现,我想不成问题。这是delphi 的代码,不过你可以修改成vbprocedure TFinput.FormKeyPress(Sender: TObject; var Key: Char);
begin  // 判断是否是回车
  If Key = #13 then begin
  //判断接收者是否是tdbgrid
  if not (activeControl is Tdbgrid) then begin
   //此键盘消息不再由其他程序处理
   key :=#0;
    //跳转道下一个空件焦点]
    perform(WM_NEXTDLGCTL,0,0);
  end
  else if (activecontrol is Tdbgrid) then
     with Tdbgrid(activecontrol) do
       if selectedindex <(fieldcount-1) then
        //跳转到下一栏
          selectedindex:=selectedindex+1
       else
          selectedindex:=0;
     end;end;

解决方案 »

  1.   

    设置属性,键盘TAB键,动作为2,自动换行单元指针,允许键头
    Private Sub DataGrid1_KeyPress(KeyAscii As Integer)
        If KeyAscii = 13 Then
            SendKeys "{tab}"
        End If
    End Sub在数据库里加一个ID 字段记录行数,按INSERT键调用插入行,插入后按行号排序实现插入
    Private Sub DataGrid1_KeyDown(KeyCode As Integer, Shift As Integer)
        If KeyCode = 45 Then
            DataGrid1.Enabled = False
            Call RsInsert(Rs_Jc_Shhy_Sp, Rs_Jc_Shhy_Sp.Fields.Count)
            DataGrid1.Enabled = True
        End If
    End SubPrivate Sub RsInsert(Rs_WillInsert As ADODB.Recordset, ii As Integer)
        Dim nNowRow As Integer
        Dim nLines As Integer
        
        With Rs_WillInsert
            nLines = .Fields("id")
            '.Sort = "id"
            '.Find "id=" & nLines
            Do While Not .EOF
                .Fields("id") = .Fields("id") + 1
                .MoveNext
            Loop
            
            .AddNew
            .Fields("hth") = Text1(0).Text
            .Fields("id") = nLines
            .Sort = "id"
        End With
    End Sub'当行列改变时,combo1的visible为true或false,高度随行改变
    Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
    Select Case DataGrid1.Col
        Case 0
            Check1.Visible = False
            Text5.Visible = False
            Combo2.Visible = True
            Combo4.Visible = False
            
            Combo2.Width = DataGrid1.Columns(DataGrid1.Col).Width + 50
            Combo2.Left = DataGrid1.Left + DataGrid1.Columns(DataGrid1.Col).Left
            Combo2.Top = DataGrid1.Top + DataGrid1.Row * (DataGrid1.RowHeight + hh) + (DataGrid1.HeadLines - 1) * 195
            Combo2.SetFocus
            If DataGrid1.Columns(0).Text <> "" Then
                Combo2.Text = DataGrid1.Columns(0).Text
            End If
    End Select
    End Sub
    '我的oicq:21177563
    'e_mail:[email protected]
      

  2.   

    另外使用Rs.addnew就可增加记录,插入我使用的上一种办法,删除功能网格自带
      

  3.   

    多谢各位老兄,另,请IUPRG(幕后工作者)有空时将电脑编程技巧 2001,11期 p45页贴给我, 我就可以结帖子了。