CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2001
    Posts
    17

    Freezing a Datagrid Column


    How can I freeze one or several columns in a data grid while scrolling horizonally ? (As the "Freeze" option for columns in an Access grid)

    Thanks,
    Yaron.




  2. #2
    Join Date
    May 2001
    Location
    Canada
    Posts
    182

    Re: Freezing a Datagrid Column

    Hi,
    DataGrid doesn't have so flexiable feature as MSFlexGrid on this issue. What I did before is using the Splits property of DataGrid.
    First, on the form layout, split the grid to two splits. And then use a proper DataSource.
    In codes, connect to DB first, and then call Grid1.Rebind. The last thing is creating a function like following to do some make-up on the grid.
    =========
    Sub FormatGrid()
    '
    'Lock some columns as you said
    '
    Const LockedItems = 4

    '
    'Hide the right part columns in the left split
    '
    For i = LockedItems To Grid1.Splits(0).Columns.count - 1
    Grid1.Splits(0).Columns(i).Visible = False
    Next i

    '
    'Show the right part columns in the right split
    '
    For i = LockedItems To Grid1.Splits(1).Columns.count - 1
    Grid1.Splits(1).Columns(i).Visible = True
    Grid1.Splits(1).Columns(i).Alignment = 2
    Next i

    '
    'Show the left part columns in the left split, and hide in the right split
    '
    For i = 0 To LockedItems - 1
    Grid1.Splits(0).Columns(i).Visible = True
    Grid1.Splits(0).Columns(i).Alignment = 2
    Grid1.Splits(1).Columns(i).Visible = False
    Next i

    '''''''Refresh Grid''''''''
    Grid1.Refresh

    '
    'set focus to the right split
    '
    Grid1.Split = 1

    End Sub
    ========
    For more information, please look up MSDN, key words: DataGrid and Splits property.

    Regards,

    Michi

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured