Flex网格不可编辑的列

时间:2012-01-15 04:47:05

标签: vb6

我不想编辑flex gird中的某些列。

Flex Grid

column1, column2, .... column35

我想仅从column1 ... column10进行编辑,剩下的列我不想编辑或输入。

如何在vb6中完成。

2 个答案:

答案 0 :(得分:0)

我相信MS Flex Grid专为显示数据而非编辑而设计。如果需要编辑单元格数据,可以使用Flex Grid在运行时叠加文本框以捕获用户数据条目并在代码中设置单元格的“Text”属性。否则,您可以选择使用其他控件。

以下是上述方法的一些示例:

http://support.microsoft.com/kb/241355

http://www.vb-helper.com/howto_edit_flexgrid_control.html

答案 1 :(得分:0)

我在VB6中将一个特殊的用户控件设置为可编辑的网格。如果你愿意,我可以寄给你一份。

我用来编辑单元格的代码如下:

Private Sub fg_KeyDown(KeyCode As Integer, Shift As Integer)
    Dim Cancel As Boolean
    Dim Idc As Long
    Dim x

    If KeyCode = vbKeyEscape And Shift = 0 Then
        If Not fgLocked Then
            If fgRowChanged Then
                RaiseEvent BeforeRestoreBuffer
                For Idc = 1 To UBound(fgBuffer)
                    x = fgBuffer(Idc)
                    fgValues(Idc, fg.Row) = x
                    If fgColFormat(Idc) = "*" And fgBuffer(Idc) <> "" Then
                        fg.TextMatrix(fg.Row, Idc) = "*******"
                    ElseIf fgColFormat(Idc) = "RTF" Then
                        fg.TextMatrix(fg.Row, Idc) = Format(fgBuffer(Idc), "")
                    Else
                        fg.TextMatrix(fg.Row, Idc) = Format(fgBuffer(Idc), fgColFormat(Idc))
                    End If
                Next
                fgRowChanged = False
                RaiseEvent RestoreBuffer
            End If
        End If
    ElseIf KeyCode = vbKeyReturn And Shift = 0 Then
        NextCell
    ElseIf KeyCode = vbKeyF2 And Shift = 0 Then
        If Not fgLocked Then
            If fgColFormat(fg.Col) = "RTF" Then
                CellEditBig fgValues(fg.Col, fg.Row)
            Else
                CellEdit fgValues(fg.Col, fg.Row)
            End If
        End If
    ElseIf KeyCode = vbKeyF2 And Shift = vbShiftMask Then
        If Not fgLocked Then
            CellEditBig fgValues(fg.Col, fg.Row)
        End If
    ElseIf KeyCode = vbKeyDelete And Shift = 0 Then
        If Not fgLocked Then
            RaiseEvent BeforeDelete(Cancel)
            If Not Cancel Then
                If fg.Rows = fg.FixedRows + 1 Then
                    fg.AddItem ""
                    If fgRowNumber Then fg.TextMatrix(fg.Rows - 1, 0) = fg.Rows - 1
                    fgValues_AddItem ""
                End If
                fg.RemoveItem fg.Row
                If fgRowNumber Then Renumera
                fgValues_RemoveItem fg.Row
                LoadBuffer fg.Row
                RaiseEvent AfterDelete
            End If
        End If
    ElseIf KeyCode = vbKeyInsert And Shift = 0 Then
        If Not fgLocked Then
            RaiseEvent BeforeInsert(Cancel)
            If Not Cancel Then
                fg.AddItem "", fg.Row
                If fgRowNumber Then Renumera
                fgValues_AddItem "", fg.Row
                RaiseEvent AfterInsert
            End If
        End If
    Else
        RaiseEvent KeyDown(KeyCode, Shift)
    End If
End Sub