如何让MSHflexGrid控件自动序号在显示记录时自动显示序号

解决方案 »

  1.   

    Private Sub Command1_Click()
        Dim cn As New ADODB.Connection
        Dim rs As New ADODB.Recordset
        Dim i As Integer    cn.CursorLocation = adUseClient
        cn.Open ""    rs.Open "", cn, adOpenStatic, adLockOptimistic    If rs.RecordCount > 0 Then
            i = 0
            With MSFlexGrid1
                .Rows = rs.RecordCount + 1
                .Cols = rs.Fields.Count + 1
                
                While Not rs.EOF
                    i = i + 1
                    .Row = i                .Col = 0
                    .Text = i
                    For j = 1 To rs.Fields.Count
                        .Col = j
                        .Text = rs.Fields(j - 1)
                    Next j                rs.MoveNext
                Wend
            End With
        End IfEnd Sub
      

  2.   

    Private Sub Command1_Click()
        Dim cn As New ADODB.Connection
        Dim rs As New ADODB.Recordset
        Dim i As Integer    cn.CursorLocation = adUseClient
        cn.Open ""    rs.Open "", cn, adOpenStatic, adLockOptimistic    If rs.RecordCount > 0 Then
            i = 0
            With MSFlexGrid1
                .Rows = rs.RecordCount + 1
                .Cols = rs.Fields.Count + 1
                
                While Not rs.EOF
                    i = i + 1
                    .Row = i                .Col = 0
                    .Text = i
                    For j = 1 To rs.Fields.Count
                        .Col = j
                        .Text = rs.Fields(j - 1)
                    Next j                rs.MoveNext
                Wend
            End With
        End IfEnd Sub