如题!!

解决方案 »

  1.   


        增加 MsFlexGrid 的编辑功能
     
     概述
    MsFlexGrid 控件没有提供文本编辑的功能,下面的例子演示了如何利用一个TextBox 实现编辑当前网格的功能。在按下一个键后, 就把TextBox 移动到当前的位置, 并激活。 在键入回车或移动到其他网格时, 就把TextBox 中的内容放到网格中。 实现步骤
    1 打开 VB5, 开启一个新的工程。2 在菜单“工程” 中选择 “部件”, 在列表中选中 “Microsoft FlexGrid Control ..”3 放一个 MsFlexGrid 控件和一个TextBox 控件(Text1)到 Form1。 修改MsFlexGrid 控件的名称为 Grid1, 设置Grid1 的行,列 为 4, 固定行,列为 0。 设置 Text1 的 Visiable 为 False, BorderStyle 为 None(0)。4 在Form1 的代码中增加声明:Const ASC_ENTER = 13 '回车
    Dim gRow As Integer
    Dim gCol As Integer5 增加代码到 Grid_KeyPress 过程:Private Sub Grid1_KeyPress(KeyAscii As Integer)
    ' Move the text box to the current grid cell:
    Text1.Top = Grid1.CellTop + Grid1.Top
    Text1.Left = Grid1.CellLeft + Grid1.Left
    ' Save the position of the grids Row and Col for later:
    gRow = Grid1.Row
    gCol = Grid1.Col
    ' Make text box same size as current grid cell:
    Text1.Width = Grid1.CellWidth - 2 * Screen.TwipsPerPixelX
    Text1.Height = Grid1.CellHeight - 2 * Screen.TwipsPerPixelY
    ' Transfer the grid cell text:
    Text1.Text = Grid1.Text
    ' Show the text box:
    Text1.Visible = True
    Text1.ZOrder 0 ' 把 Text1 放到最前面!
    Text1.SetFocus
    ' Redirect this KeyPress event to the text box:
    If KeyAscii <> ASC_ENTER Then
    SendKeys Chr$(KeyAscii)
    End If
    End Sub6 增加代码到 Text1_KeyPress 过程:Private Sub Text1_KeyPress(KeyAscii As Integer)
    If KeyAscii = ASC_ENTER Then
    Grid1.SetFocus ' Set focus back to grid, see Text_LostFocus.
    KeyAscii = 0 ' Ignore this KeyPress.
    End If
    End Sub7 增加代码到 Text1_LostFocus 过程:Private Sub Text1_LostFocus()
    Dim tmpRow As Integer
    Dim tmpCol As Integer
    ' Save current settings of Grid Row and col. This is needed only if
    ' the focus is set somewhere else in the Grid.
    tmpRow = Grid1.Row
    tmpCol = Grid1.Col
    ' Set Row and Col back to what they were before Text1_LostFocus:
    Grid1.Row = gRow
    Grid1.Col = gCol
    Grid1.Text = Text1.Text ' Transfer text back to grid.
    Text1.SelStart = 0 ' Return caret to beginning.
    Text1.Visible = False ' Disable text box.
    ' Return row and Col contents:
    Grid1.Row = tmpRow
    Grid1.Col = tmpCol
    End Sub8 好了。 按 F5 开始测试。 您可以自由地在 Grid 中移动, 按回车可以开始或结束编辑。 
     
       
     
      
     
      

  2.   

    edittable=true就可以进行编辑了
      

  3.   

    在MSFLEXGRID控件中每一个CELL格的内容是不可以由用户直接编辑的但是我们可以通过一些小技
    巧来方便的实现这编辑功能来扩展MSFLEXGRID的应用(在实际应用中这是很常用的功能)。    你只需按下面的做即可轻松实现编辑MSFLEXGRID控件数据的功能    例在窗体上放一文本框text1,和一MSFLEXGRID控件flexgrid1
    加入下例代码
    Private Sub Form_Load()
        Text1.Move -10000, -10000, 1, 1
    End SubPrivate Sub MSFlexGrid1_EnterCell()
        MSFlexGrid1.CellBackColor = vbBlue
        MSFlexGrid1.CellForeColor = vbWhite
        Text1.Text = MSFlexGrid1.Text
        Text1.SelStart = 0
        Text1.SelLength = Len(Text1.Text)
    End SubPrivate Sub MSFlexGrid1_LeaveCell()
        MSFlexGrid1.CellBackColor = vbWhite
        MSFlexGrid1.CellForeColor = vbBlue
    End SubPrivate Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
        Text1.SetFocus
    End SubPrivate Sub Text1_Change()
        MSFlexGrid1.Text = Text1.Text
    End SubPrivate Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
        Select Case KeyCode
            Case vbKeyLeft, vbKeyRight, vbKeyUp, vbKeyDown
                KeyCode = 0
        End Select
    End Sub
        ok,这样一个可编辑的MSFLEXGRID控件就完成了,简单吧!!
      

  4.   

    还是在它的keyascii事件中做处理吧.
    让它
    grid.textmari(row,col)=grid.textmari(row,col) & chr(keyascii)
      

  5.   

    用supergrid控件直接就可以了,那要那么麻烦。
      

  6.   

    除此以外,还可以使用第三方控件
    象你推荐一个:http://junwhj.myrice.com/
    中国人自己开发的
    XP风格
    有完整的帮助文件
    最重要的是:目前免费
      

  7.   

    我有简单的方法,你可以双击单元格就可以修改,记者要给分哦
    下面是例子:
    Private Sub Form_Load()
        
        Dim i As Integer
        For i = 1 To 5
            MSFlexGrid1.AddItem vbTab & "a" & i & vbTab & "b" & i & vbTab & "c" & i & vbTab & "d" & i & vbTab & "e" & i
        Next
        Text1.Visible = faleEnd SubPrivate Sub MSFlexGrid1_DblClick()
        Text1.Visible = True
        Text1.Width = MSFlexGrid1.ColWidth(MSFlexGrid1.Col)
        Text1.Left = MSFlexGrid1.CellLeft
        Text1.Top = MSFlexGrid1.CellTop
        Text1.Text = MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, MSFlexGrid1.Col)
        Text1.SetFocus
        Text1.SelStart = 0
        Text1.SelLength = Len(Text1.Text)End SubPrivate Sub MSFlexGrid1_LeaveCell()
        MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, MSFlexGrid1.Col) = Text1.Text
    End Sub
      

  8.   

    lihonggen0
    可以详细解释一下吗?
    另,使用EnterCell事件,只要msflexgrid的单元格内容改变都会激活这一事件,而这却不是我们希望的,可以说要让msflexgrid getfocus后才激活,但是,单击msflexgrid并不一定让msflexgrid获得焦点,而单击其它地方也不一定让msflexgrid lostfocus.
      

  9.   

    同理,使用leavecell事件也会遇到同样的情况,应如何进行控制呢?