Freeze Column in DataGrid

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Agnes

    Freeze Column in DataGrid

    I understand it is impossible, but still curious to know "Can I freeze
    several column in the datagrid, the user can only scroll the first 3 columns
    (not verical), for the rest of the coulumn, it is freeze.


  • Rulin Hong

    #2
    RE: Freeze Column in DataGrid

    Try use two datagrids: one is for freeze, another is for scroll.

    "Agnes" wrote:
    [color=blue]
    > I understand it is impossible, but still curious to know "Can I freeze
    > several column in the datagrid, the user can only scroll the first 3 columns
    > (not verical), for the rest of the coulumn, it is freeze.
    >
    >
    >[/color]

    Comment

    • Ken Tucker [MVP]

      #3
      Re: Freeze Column in DataGrid

      Hi,

      Here is a column style that locks a column on the datagrid. It is
      still under development. basically if you set the locked property to true
      it places a panel over the datagrid that has the locked column drawn on it.
      Currently it only will lock the first column.

      Imports System.Drawing. Drawing2D

      Public Class ColoredGridColu mn

      Inherits DataGridTextBox Column

      Dim mForeColor As Color = Color.Black

      Dim mBackColor As Color = Color.White

      Dim WithEvents mctrl As DblBufferPanel

      Dim WithEvents dg As DataGrid

      Dim pt As New Point

      Dim bPanelOnly As Boolean = False

      Dim cm As CurrencyManager

      Dim ar As Boolean

      Private Class DblBufferPanel

      Inherits Panel

      Public Sub New()

      Me.SetStyle(Con trolStyles.Doub leBuffer, True)

      End Sub

      End Class

      Public Property ForeColor() As Color

      Get

      Return mForeColor

      End Get

      Set(ByVal Value As Color)

      mForeColor = Value

      End Set

      End Property

      Public Property BackColor() As Color

      Get

      Return mBackColor

      End Get

      Set(ByVal Value As Color)

      mBackColor = Value

      End Set

      End Property

      Public Property Locked() As Boolean

      Get

      Return Not mctrl Is Nothing

      End Get

      Set(ByVal Value As Boolean)

      If Value = False Then

      mctrl = Nothing

      Else

      mctrl = New DblBufferPanel

      End If

      End Set

      End Property

      Protected Overloads Overrides Sub Paint(ByVal g As System.Drawing. Graphics,
      ByVal bounds As System.Drawing. Rectangle, ByVal source As
      System.Windows. Forms.CurrencyM anager, ByVal rowNum As Integer, ByVal
      backBrush As System.Drawing. Brush, ByVal foreBrush As System.Drawing. Brush,
      ByVal alignToRight As Boolean)

      Dim brFore As Brush

      Dim brBack As Brush

      Dim cFore As Color

      Dim cBack As Color

      Static bPainted As Boolean = False

      If Not bPainted And Not (mctrl Is Nothing) Then

      dg = Me.DataGridTabl eStyle.DataGrid

      dg.Parent.Contr ols.Add(mctrl)

      MovePanel()

      mctrl.BringToFr ont()

      pt = dg.GetCellBound s(0, 0).Location

      If TypeOf dg.DataSource Is DataTable Then

      AddHandler DirectCast(dg.D ataSource, DataTable).Defa ultView.ListCha nged,
      AddressOf dv_ListChanged

      ElseIf TypeOf dg.DataSource Is DataView Then

      AddHandler DirectCast(dg.D ataSource, DataView).ListC hanged, AddressOf
      dv_ListChanged

      End If

      End If

      cm = source

      ar = alignToRight

      bPainted = True

      If Me.DataGridTabl eStyle.DataGrid .IsSelected(row Num) Then

      cFore = Me.DataGridTabl eStyle.Selectio nForeColor

      cBack = Me.DataGridTabl eStyle.Selectio nBackColor

      Else

      cFore = ForeColor

      cBack = BackColor

      End If

      brBack = New LinearGradientB rush(bounds, cBack, Color.White, 90, False)

      brFore = New SolidBrush(cFor e)



      Dim bl As New Blend

      bl.Factors = New Single() {0.0F, 0.1F, 0.5F, 0.7F, 0.7F, 0.5F, 0.3F, 0.2F,
      0}

      bl.Positions = New Single() {0, 0.1F, 0.2F, 0.5F, 0.6F, 0.7F, 0.8F, 0.9F,
      1.0F}

      DirectCast(brBa ck, LinearGradientB rush).Blend = bl

      If Not bPanelOnly Then

      MyBase.Paint(g, bounds, source, rowNum, brBack, brFore, alignToRight)

      End If

      If Not (mctrl Is Nothing) Then

      ' if there is another control to draw on move the bounds to the right edge
      if htere is not then it will ignore that directive right? yesgot oitf the
      control

      'mctrl.Backgrou ndImage = bm

      PaintRow(mctrl. CreateGraphics, bounds, rowNum)

      End If

      If Me.GetColumnVal ueAtRow(source, rowNum).ToStrin g = "Davolio" Then

      Me.DataGridTabl eStyle.DataGrid .Select(rowNum)

      End If

      End Sub

      Public Shadows Sub BeginUpdate()

      MyBase.BeginUpd ate()

      End Sub

      Public Shadows Sub EndUpdate()

      MyBase.EndUpdat e()

      End Sub

      Protected Overloads Overrides Sub Edit(ByVal source As
      System.Windows. Forms.CurrencyM anager, ByVal rowNum As Integer, ByVal bounds
      As System.Drawing. Rectangle, ByVal [readOnly] As Boolean, ByVal instantText
      As String, ByVal cellIsVisible As Boolean)

      MyBase.Edit(sou rce, rowNum, bounds, [readOnly], instantText, cellIsVisible)

      MyBase.TextBox. ForeColor = ForeColor()

      MyBase.TextBox. BackColor = BackColor

      End Sub

      Public Sub New()

      End Sub

      Private Sub dg_Scroll(ByVal sender As Object, ByVal e As System.EventArg s)
      Handles dg.Scroll

      Trace.WriteLine ("Scroll")

      RedrawPanel()

      End Sub

      Private Sub MovePanel()

      mctrl.Location = New Point(dg.Left + dg.RowHeaderWid th + 2, dg.Top + 21)

      Dim intFactor As Integer = SystemInformati on.HorizontalSc rollBarHeight

      For Each ctrl As Control In Me.DataGridTabl eStyle.DataGrid .Controls

      If TypeOf ctrl Is HScrollBar Then

      If Not DirectCast(ctrl , HScrollBar).Vis ible Then intFactor = 0

      End If

      Next

      mctrl.Height = dg.Height - 21 - intFactor - 2

      End Sub

      Private Sub dg_Move(ByVal sender As Object, ByVal e As System.EventArg s)
      Handles dg.Move

      MovePanel()

      End Sub

      Private Sub PreparePanel()

      Dim sf As New StringFormat

      sf.LineAlignmen t = StringAlignment .Center

      Dim rDraw As New RectangleF(0, 0, Me.Width, 20)

      Dim g As Graphics = mctrl.CreateGra phics

      g.Clear(mctrl.B ackColor)

      Try

      g.DrawString(Me .HeaderText, dg.Font, Brushes.Black, rDraw, sf)

      ControlPaint.Dr awBorder3D(g, _

      New Rectangle(0, 0, Me.Width, 19), Border3DStyle.R aisedInner)

      Catch

      End Try

      End Sub

      Private Sub dv_ListChanged( ByVal sender As Object, ByVal e As
      System.Componen tModel.ListChan gedEventArgs)

      'PreparePanel()

      RedrawPanel()

      End Sub

      Private Sub dg_VisibleChang ed(ByVal sender As Object, ByVal e As
      System.EventArg s) Handles dg.VisibleChang ed

      Try

      mctrl.Visible = dg.Visible

      Catch ex As Exception

      End Try

      End Sub

      Private Sub dg_SizeChanged( ByVal sender As Object, ByVal e As
      System.EventArg s) Handles dg.SizeChanged

      MovePanel()

      RedrawPanel()

      End Sub

      Private Sub RedrawPanel()

      Static oldTop As Integer = 0

      If Not mctrl Is Nothing And dg.VisibleRowCo unt > 0 Then

      Application.DoE vents()

      Dim hti As DataGrid.HitTes tInfo = dg.HitTest(pt)

      Dim newRow As Integer = hti.Row

      Trace.WriteLine (String.Format( "First Row {0} Visible rows {1}", hti.Row,
      dg.VisibleRowCo unt))

      oldTop = newRow

      bPanelOnly = True

      For x As Integer = oldTop To oldTop + dg.VisibleRowCo unt - 1

      If x < cm.Count Then

      Trace.WriteLine (String.Format( "Drawing Row {0} {1}", x, dg.GetCellBound s(x,
      dg.FirstVisible Column)))

      Paint(Nothing, dg.GetCellBound s(x, dg.FirstVisible Column), _

      cm, x, Nothing, Nothing, ar)

      End If

      Next

      bPanelOnly = False

      End If

      End Sub

      Private Sub dg_Resize(ByVal sender As Object, ByVal e As System.EventArg s)
      Handles dg.Resize

      MovePanel()

      End Sub

      Private Sub mctrl_Paint(ByV al sender As Object, ByVal e As
      System.Windows. Forms.PaintEven tArgs) Handles mctrl.Paint

      Dim sf As New StringFormat

      sf.LineAlignmen t = StringAlignment .Center

      Dim rDraw As New RectangleF(0, 0, Me.Width, 20)

      Dim g As Graphics = e.Graphics

      g.Clear(mctrl.B ackColor)

      Try

      g.DrawString(Me .HeaderText, dg.Font, Brushes.Black, rDraw, sf)

      ControlPaint.Dr awBorder3D(g, _

      New Rectangle(0, 0, Me.Width, 19), Border3DStyle.R aisedInner)

      Debug.WriteLine ("Panel Paint")

      Dim hti As DataGrid.HitTes tInfo = dg.HitTest(pt)

      Dim newRow As Integer = hti.Row

      Dim oldTop As Integer

      Trace.WriteLine (String.Format( "First Row {0} Visible rows {1}", hti.Row,
      dg.VisibleRowCo unt))

      oldTop = newRow

      bPanelOnly = True

      For x As Integer = oldTop To oldTop + dg.VisibleRowCo unt - 1

      If x < cm.Count Then

      Trace.WriteLine (String.Format( "Drawing Row {0} {1}", x, dg.GetCellBound s(x,
      dg.FirstVisible Column)))

      Paint(Nothing, dg.GetCellBound s(x, dg.FirstVisible Column), _

      cm, x, Nothing, Nothing, ar)

      End If

      Next

      Catch

      End Try

      End Sub

      Private Sub PaintRow(ByVal g As Graphics, ByVal bounds As Rectangle, ByVal
      rownum As Integer)

      Dim brFore As Brush

      Dim brBack As Brush

      Dim cFore As Color

      Dim cBack As Color

      Dim bounds2 As New Rectangle(0, bounds.Y - 21, bounds.Width, bounds.Height)

      If Me.DataGridTabl eStyle.DataGrid .IsSelected(row num) Then

      cFore = Me.DataGridTabl eStyle.Selectio nForeColor

      cBack = Me.DataGridTabl eStyle.Selectio nBackColor

      Else

      cFore = ForeColor

      cBack = BackColor

      End If

      brBack = New LinearGradientB rush(bounds, cBack, Color.White, 90, False)

      brFore = New SolidBrush(cFor e)



      Dim bl As New Blend

      bl.Factors = New Single() {0.0F, 0.1F, 0.5F, 0.7F, 0.7F, 0.5F, 0.3F, 0.2F,
      0}

      bl.Positions = New Single() {0, 0.1F, 0.2F, 0.5F, 0.6F, 0.7F, 0.8F, 0.9F,
      1.0F}

      DirectCast(brBa ck, LinearGradientB rush).Blend = bl

      If mctrl.Width <> Me.Width Then mctrl.Width = Me.Width

      MyBase.Paint(g, bounds2, cm, rownum, _

      brBack, brFore, ar)

      If rownum = cm.Count - 1 Then

      Dim br As New SolidBrush(Me.D ataGridTableSty le.DataGrid.Bac kgroundColor)

      g.FillRectangle (br, 0, bounds2.Bottom + 1, mctrl.Width, _

      mctrl.Height - bounds2.Bottom - 1)

      End If

      End Sub

      End Class



      Ken

      -------------------------------

      "Agnes" <agnes@dynamict ech.com.hk> wrote in message
      news:uCN6kFPwEH A.3012@TK2MSFTN GP10.phx.gbl...
      I understand it is impossible, but still curious to know "Can I freeze
      several column in the datagrid, the user can only scroll the first 3 columns
      (not verical), for the rest of the coulumn, it is freeze.



      Comment

      • scorpion53061

        #4
        Re: Freeze Column in DataGrid

        This is nothing short of amazing work Ken.



        "Ken Tucker [MVP]" <vb2ae@bellsout h.net> wrote in message
        news:vb2ae@bell south.net:[color=blue]
        > Hi,
        >
        > Here is a column style that locks a column on the datagrid. It is
        >
        > still under development. basically if you set the locked property to true
        >
        > it places a panel over the datagrid that has the locked column drawn on
        > it.
        > Currently it only will lock the first column.
        >
        > Imports System.Drawing. Drawing2D
        >
        > Public Class ColoredGridColu mn
        >
        > Inherits DataGridTextBox Column
        >
        > Dim mForeColor As Color = Color.Black
        >
        > Dim mBackColor As Color = Color.White
        >
        > Dim WithEvents mctrl As DblBufferPanel
        >
        > Dim WithEvents dg As DataGrid
        >
        > Dim pt As New Point
        >
        > Dim bPanelOnly As Boolean = False
        >
        > Dim cm As CurrencyManager
        >
        > Dim ar As Boolean
        >
        > Private Class DblBufferPanel
        >
        > Inherits Panel
        >
        > Public Sub New()
        >
        > Me.SetStyle(Con trolStyles.Doub leBuffer, True)
        >
        > End Sub
        >
        > End Class
        >
        > Public Property ForeColor() As Color
        >
        > Get
        >
        > Return mForeColor
        >
        > End Get
        >
        > Set(ByVal Value As Color)
        >
        > mForeColor = Value
        >
        > End Set
        >
        > End Property
        >
        > Public Property BackColor() As Color
        >
        > Get
        >
        > Return mBackColor
        >
        > End Get
        >
        > Set(ByVal Value As Color)
        >
        > mBackColor = Value
        >
        > End Set
        >
        > End Property
        >
        > Public Property Locked() As Boolean
        >
        > Get
        >
        > Return Not mctrl Is Nothing
        >
        > End Get
        >
        > Set(ByVal Value As Boolean)
        >
        > If Value = False Then
        >
        > mctrl = Nothing
        >
        > Else
        >
        > mctrl = New DblBufferPanel
        >
        > End If
        >
        > End Set
        >
        > End Property
        >
        > Protected Overloads Overrides Sub Paint(ByVal g As
        > System.Drawing. Graphics,
        > ByVal bounds As System.Drawing. Rectangle, ByVal source As
        > System.Windows. Forms.CurrencyM anager, ByVal rowNum As Integer, ByVal
        > backBrush As System.Drawing. Brush, ByVal foreBrush As
        > System.Drawing. Brush,
        > ByVal alignToRight As Boolean)
        >
        > Dim brFore As Brush
        >
        > Dim brBack As Brush
        >
        > Dim cFore As Color
        >
        > Dim cBack As Color
        >
        > Static bPainted As Boolean = False
        >
        > If Not bPainted And Not (mctrl Is Nothing) Then
        >
        > dg = Me.DataGridTabl eStyle.DataGrid
        >
        > dg.Parent.Contr ols.Add(mctrl)
        >
        > MovePanel()
        >
        > mctrl.BringToFr ont()
        >
        > pt = dg.GetCellBound s(0, 0).Location
        >
        > If TypeOf dg.DataSource Is DataTable Then
        >
        > AddHandler DirectCast(dg.D ataSource, DataTable).Defa ultView.ListCha nged,
        >
        > AddressOf dv_ListChanged
        >
        > ElseIf TypeOf dg.DataSource Is DataView Then
        >
        > AddHandler DirectCast(dg.D ataSource, DataView).ListC hanged, AddressOf
        > dv_ListChanged
        >
        > End If
        >
        > End If
        >
        > cm = source
        >
        > ar = alignToRight
        >
        > bPainted = True
        >
        > If Me.DataGridTabl eStyle.DataGrid .IsSelected(row Num) Then
        >
        > cFore = Me.DataGridTabl eStyle.Selectio nForeColor
        >
        > cBack = Me.DataGridTabl eStyle.Selectio nBackColor
        >
        > Else
        >
        > cFore = ForeColor
        >
        > cBack = BackColor
        >
        > End If
        >
        > brBack = New LinearGradientB rush(bounds, cBack, Color.White, 90, False)
        >
        > brFore = New SolidBrush(cFor e)
        >
        >
        >
        > Dim bl As New Blend
        >
        > bl.Factors = New Single() {0.0F, 0.1F, 0.5F, 0.7F, 0.7F, 0.5F, 0.3F, 0.2F,
        >
        > 0}
        >
        > bl.Positions = New Single() {0, 0.1F, 0.2F, 0.5F, 0.6F, 0.7F, 0.8F, 0.9F,
        >
        > 1.0F}
        >
        > DirectCast(brBa ck, LinearGradientB rush).Blend = bl
        >
        > If Not bPanelOnly Then
        >
        > MyBase.Paint(g, bounds, source, rowNum, brBack, brFore, alignToRight)
        >
        > End If
        >
        > If Not (mctrl Is Nothing) Then
        >
        > ' if there is another control to draw on move the bounds to the right edge
        >
        > if htere is not then it will ignore that directive right? yesgot oitf the
        >
        > control
        >
        > 'mctrl.Backgrou ndImage = bm
        >
        > PaintRow(mctrl. CreateGraphics, bounds, rowNum)
        >
        > End If
        >
        > If Me.GetColumnVal ueAtRow(source, rowNum).ToStrin g = "Davolio" Then
        >
        > Me.DataGridTabl eStyle.DataGrid .Select(rowNum)
        >
        > End If
        >
        > End Sub
        >
        > Public Shadows Sub BeginUpdate()
        >
        > MyBase.BeginUpd ate()
        >
        > End Sub
        >
        > Public Shadows Sub EndUpdate()
        >
        > MyBase.EndUpdat e()
        >
        > End Sub
        >
        > Protected Overloads Overrides Sub Edit(ByVal source As
        > System.Windows. Forms.CurrencyM anager, ByVal rowNum As Integer, ByVal
        > bounds
        > As System.Drawing. Rectangle, ByVal [readOnly] As Boolean, ByVal
        > instantText
        > As String, ByVal cellIsVisible As Boolean)
        >
        > MyBase.Edit(sou rce, rowNum, bounds, [readOnly], instantText,
        > cellIsVisible)
        >
        > MyBase.TextBox. ForeColor = ForeColor()
        >
        > MyBase.TextBox. BackColor = BackColor
        >
        > End Sub
        >
        > Public Sub New()
        >
        > End Sub
        >
        > Private Sub dg_Scroll(ByVal sender As Object, ByVal e As System.EventArg s)
        >
        > Handles dg.Scroll
        >
        > Trace.WriteLine ("Scroll")
        >
        > RedrawPanel()
        >
        > End Sub
        >
        > Private Sub MovePanel()
        >
        > mctrl.Location = New Point(dg.Left + dg.RowHeaderWid th + 2, dg.Top + 21)
        >
        > Dim intFactor As Integer = SystemInformati on.HorizontalSc rollBarHeight
        >
        > For Each ctrl As Control In Me.DataGridTabl eStyle.DataGrid .Controls
        >
        > If TypeOf ctrl Is HScrollBar Then
        >
        > If Not DirectCast(ctrl , HScrollBar).Vis ible Then intFactor = 0
        >
        > End If
        >
        > Next
        >
        > mctrl.Height = dg.Height - 21 - intFactor - 2
        >
        > End Sub
        >
        > Private Sub dg_Move(ByVal sender As Object, ByVal e As System.EventArg s)
        >
        > Handles dg.Move
        >
        > MovePanel()
        >
        > End Sub
        >
        > Private Sub PreparePanel()
        >
        > Dim sf As New StringFormat
        >
        > sf.LineAlignmen t = StringAlignment .Center
        >
        > Dim rDraw As New RectangleF(0, 0, Me.Width, 20)
        >
        > Dim g As Graphics = mctrl.CreateGra phics
        >
        > g.Clear(mctrl.B ackColor)
        >
        > Try
        >
        > g.DrawString(Me .HeaderText, dg.Font, Brushes.Black, rDraw, sf)
        >
        > ControlPaint.Dr awBorder3D(g, _
        >
        > New Rectangle(0, 0, Me.Width, 19), Border3DStyle.R aisedInner)
        >
        > Catch
        >
        > End Try
        >
        > End Sub
        >
        > Private Sub dv_ListChanged( ByVal sender As Object, ByVal e As
        > System.Componen tModel.ListChan gedEventArgs)
        >
        > 'PreparePanel()
        >
        > RedrawPanel()
        >
        > End Sub
        >
        > Private Sub dg_VisibleChang ed(ByVal sender As Object, ByVal e As
        > System.EventArg s) Handles dg.VisibleChang ed
        >
        > Try
        >
        > mctrl.Visible = dg.Visible
        >
        > Catch ex As Exception
        >
        > End Try
        >
        > End Sub
        >
        > Private Sub dg_SizeChanged( ByVal sender As Object, ByVal e As
        > System.EventArg s) Handles dg.SizeChanged
        >
        > MovePanel()
        >
        > RedrawPanel()
        >
        > End Sub
        >
        > Private Sub RedrawPanel()
        >
        > Static oldTop As Integer = 0
        >
        > If Not mctrl Is Nothing And dg.VisibleRowCo unt > 0 Then
        >
        > Application.DoE vents()
        >
        > Dim hti As DataGrid.HitTes tInfo = dg.HitTest(pt)
        >
        > Dim newRow As Integer = hti.Row
        >
        > Trace.WriteLine (String.Format( "First Row {0} Visible rows {1}", hti.Row,
        >
        > dg.VisibleRowCo unt))
        >
        > oldTop = newRow
        >
        > bPanelOnly = True
        >
        > For x As Integer = oldTop To oldTop + dg.VisibleRowCo unt - 1
        >
        > If x < cm.Count Then
        >
        > Trace.WriteLine (String.Format( "Drawing Row {0} {1}", x,
        > dg.GetCellBound s(x,
        > dg.FirstVisible Column)))
        >
        > Paint(Nothing, dg.GetCellBound s(x, dg.FirstVisible Column), _
        >
        > cm, x, Nothing, Nothing, ar)
        >
        > End If
        >
        > Next
        >
        > bPanelOnly = False
        >
        > End If
        >
        > End Sub
        >
        > Private Sub dg_Resize(ByVal sender As Object, ByVal e As System.EventArg s)
        >
        > Handles dg.Resize
        >
        > MovePanel()
        >
        > End Sub
        >
        > Private Sub mctrl_Paint(ByV al sender As Object, ByVal e As
        > System.Windows. Forms.PaintEven tArgs) Handles mctrl.Paint
        >
        > Dim sf As New StringFormat
        >
        > sf.LineAlignmen t = StringAlignment .Center
        >
        > Dim rDraw As New RectangleF(0, 0, Me.Width, 20)
        >
        > Dim g As Graphics = e.Graphics
        >
        > g.Clear(mctrl.B ackColor)
        >
        > Try
        >
        > g.DrawString(Me .HeaderText, dg.Font, Brushes.Black, rDraw, sf)
        >
        > ControlPaint.Dr awBorder3D(g, _
        >
        > New Rectangle(0, 0, Me.Width, 19), Border3DStyle.R aisedInner)
        >
        > Debug.WriteLine ("Panel Paint")
        >
        > Dim hti As DataGrid.HitTes tInfo = dg.HitTest(pt)
        >
        > Dim newRow As Integer = hti.Row
        >
        > Dim oldTop As Integer
        >
        > Trace.WriteLine (String.Format( "First Row {0} Visible rows {1}", hti.Row,
        >
        > dg.VisibleRowCo unt))
        >
        > oldTop = newRow
        >
        > bPanelOnly = True
        >
        > For x As Integer = oldTop To oldTop + dg.VisibleRowCo unt - 1
        >
        > If x < cm.Count Then
        >
        > Trace.WriteLine (String.Format( "Drawing Row {0} {1}", x,
        > dg.GetCellBound s(x,
        > dg.FirstVisible Column)))
        >
        > Paint(Nothing, dg.GetCellBound s(x, dg.FirstVisible Column), _
        >
        > cm, x, Nothing, Nothing, ar)
        >
        > End If
        >
        > Next
        >
        > Catch
        >
        > End Try
        >
        > End Sub
        >
        > Private Sub PaintRow(ByVal g As Graphics, ByVal bounds As Rectangle, ByVal
        >
        > rownum As Integer)
        >
        > Dim brFore As Brush
        >
        > Dim brBack As Brush
        >
        > Dim cFore As Color
        >
        > Dim cBack As Color
        >
        > Dim bounds2 As New Rectangle(0, bounds.Y - 21, bounds.Width,
        > bounds.Height)
        >
        > If Me.DataGridTabl eStyle.DataGrid .IsSelected(row num) Then
        >
        > cFore = Me.DataGridTabl eStyle.Selectio nForeColor
        >
        > cBack = Me.DataGridTabl eStyle.Selectio nBackColor
        >
        > Else
        >
        > cFore = ForeColor
        >
        > cBack = BackColor
        >
        > End If
        >
        > brBack = New LinearGradientB rush(bounds, cBack, Color.White, 90, False)
        >
        > brFore = New SolidBrush(cFor e)
        >
        >
        >
        > Dim bl As New Blend
        >
        > bl.Factors = New Single() {0.0F, 0.1F, 0.5F, 0.7F, 0.7F, 0.5F, 0.3F, 0.2F,
        >
        > 0}
        >
        > bl.Positions = New Single() {0, 0.1F, 0.2F, 0.5F, 0.6F, 0.7F, 0.8F, 0.9F,
        >
        > 1.0F}
        >
        > DirectCast(brBa ck, LinearGradientB rush).Blend = bl
        >
        > If mctrl.Width <> Me.Width Then mctrl.Width = Me.Width
        >
        > MyBase.Paint(g, bounds2, cm, rownum, _
        >
        > brBack, brFore, ar)
        >
        > If rownum = cm.Count - 1 Then
        >
        > Dim br As New SolidBrush(Me.D ataGridTableSty le.DataGrid.Bac kgroundColor)
        >
        > g.FillRectangle (br, 0, bounds2.Bottom + 1, mctrl.Width, _
        >
        > mctrl.Height - bounds2.Bottom - 1)
        >
        > End If
        >
        > End Sub
        >
        > End Class
        >
        >
        >
        > Ken
        >
        > -------------------------------
        >
        > "Agnes" <agnes@dynamict ech.com.hk> wrote in message
        > news:uCN6kFPwEH A.3012@TK2MSFTN GP10.phx.gbl...
        > I understand it is impossible, but still curious to know "Can I freeze
        > several column in the datagrid, the user can only scroll the first 3
        > columns
        > (not verical), for the rest of the coulumn, it is freeze.[/color]

        Comment

        • James

          #5
          Re: Freeze Column in DataGrid

          I am looking for the same function in a web application (using a web form
          data grid). The application uses C# and heaps of data grids that have the
          first one or two columns populated with data that would be nice to have
          remain visable as the user scrolls horizontally. Of course, it would also be
          nice to have the headings remain visable as the user scrolls down the grid as
          well.

          I had a quick look at Ken's code (although I am not a VB person), but it
          seems the DataGridTextBox Column is only part of the Windows Form data grid.
          So was wondering if anyone can give me any help with this.

          Cheers,

          "Ken Tucker [MVP]" wrote:
          [color=blue]
          > Hi,
          >
          > Here is a column style that locks a column on the datagrid. It is
          > still under development. basically if you set the locked property to true
          > it places a panel over the datagrid that has the locked column drawn on it.
          > Currently it only will lock the first column.
          >
          > Imports System.Drawing. Drawing2D
          >
          > Public Class ColoredGridColu mn
          >
          > Inherits DataGridTextBox Column
          >
          > Dim mForeColor As Color = Color.Black
          >
          > Dim mBackColor As Color = Color.White
          >
          > Dim WithEvents mctrl As DblBufferPanel
          >
          > Dim WithEvents dg As DataGrid
          >
          > Dim pt As New Point
          >
          > Dim bPanelOnly As Boolean = False
          >
          > Dim cm As CurrencyManager
          >
          > Dim ar As Boolean
          >
          > Private Class DblBufferPanel
          >
          > Inherits Panel
          >
          > Public Sub New()
          >
          > Me.SetStyle(Con trolStyles.Doub leBuffer, True)
          >
          > End Sub
          >
          > End Class
          >
          > Public Property ForeColor() As Color
          >
          > Get
          >
          > Return mForeColor
          >
          > End Get
          >
          > Set(ByVal Value As Color)
          >
          > mForeColor = Value
          >
          > End Set
          >
          > End Property
          >
          > Public Property BackColor() As Color
          >
          > Get
          >
          > Return mBackColor
          >
          > End Get
          >
          > Set(ByVal Value As Color)
          >
          > mBackColor = Value
          >
          > End Set
          >
          > End Property
          >
          > Public Property Locked() As Boolean
          >
          > Get
          >
          > Return Not mctrl Is Nothing
          >
          > End Get
          >
          > Set(ByVal Value As Boolean)
          >
          > If Value = False Then
          >
          > mctrl = Nothing
          >
          > Else
          >
          > mctrl = New DblBufferPanel
          >
          > End If
          >
          > End Set
          >
          > End Property
          >
          > Protected Overloads Overrides Sub Paint(ByVal g As System.Drawing. Graphics,
          > ByVal bounds As System.Drawing. Rectangle, ByVal source As
          > System.Windows. Forms.CurrencyM anager, ByVal rowNum As Integer, ByVal
          > backBrush As System.Drawing. Brush, ByVal foreBrush As System.Drawing. Brush,
          > ByVal alignToRight As Boolean)
          >
          > Dim brFore As Brush
          >
          > Dim brBack As Brush
          >
          > Dim cFore As Color
          >
          > Dim cBack As Color
          >
          > Static bPainted As Boolean = False
          >
          > If Not bPainted And Not (mctrl Is Nothing) Then
          >
          > dg = Me.DataGridTabl eStyle.DataGrid
          >
          > dg.Parent.Contr ols.Add(mctrl)
          >
          > MovePanel()
          >
          > mctrl.BringToFr ont()
          >
          > pt = dg.GetCellBound s(0, 0).Location
          >
          > If TypeOf dg.DataSource Is DataTable Then
          >
          > AddHandler DirectCast(dg.D ataSource, DataTable).Defa ultView.ListCha nged,
          > AddressOf dv_ListChanged
          >
          > ElseIf TypeOf dg.DataSource Is DataView Then
          >
          > AddHandler DirectCast(dg.D ataSource, DataView).ListC hanged, AddressOf
          > dv_ListChanged
          >
          > End If
          >
          > End If
          >
          > cm = source
          >
          > ar = alignToRight
          >
          > bPainted = True
          >
          > If Me.DataGridTabl eStyle.DataGrid .IsSelected(row Num) Then
          >
          > cFore = Me.DataGridTabl eStyle.Selectio nForeColor
          >
          > cBack = Me.DataGridTabl eStyle.Selectio nBackColor
          >
          > Else
          >
          > cFore = ForeColor
          >
          > cBack = BackColor
          >
          > End If
          >
          > brBack = New LinearGradientB rush(bounds, cBack, Color.White, 90, False)
          >
          > brFore = New SolidBrush(cFor e)
          >
          >
          >
          > Dim bl As New Blend
          >
          > bl.Factors = New Single() {0.0F, 0.1F, 0.5F, 0.7F, 0.7F, 0.5F, 0.3F, 0.2F,
          > 0}
          >
          > bl.Positions = New Single() {0, 0.1F, 0.2F, 0.5F, 0.6F, 0.7F, 0.8F, 0.9F,
          > 1.0F}
          >
          > DirectCast(brBa ck, LinearGradientB rush).Blend = bl
          >
          > If Not bPanelOnly Then
          >
          > MyBase.Paint(g, bounds, source, rowNum, brBack, brFore, alignToRight)
          >
          > End If
          >
          > If Not (mctrl Is Nothing) Then
          >
          > ' if there is another control to draw on move the bounds to the right edge
          > if htere is not then it will ignore that directive right? yesgot oitf the
          > control
          >
          > 'mctrl.Backgrou ndImage = bm
          >
          > PaintRow(mctrl. CreateGraphics, bounds, rowNum)
          >
          > End If
          >
          > If Me.GetColumnVal ueAtRow(source, rowNum).ToStrin g = "Davolio" Then
          >
          > Me.DataGridTabl eStyle.DataGrid .Select(rowNum)
          >
          > End If
          >
          > End Sub
          >
          > Public Shadows Sub BeginUpdate()
          >
          > MyBase.BeginUpd ate()
          >
          > End Sub
          >
          > Public Shadows Sub EndUpdate()
          >
          > MyBase.EndUpdat e()
          >
          > End Sub
          >
          > Protected Overloads Overrides Sub Edit(ByVal source As
          > System.Windows. Forms.CurrencyM anager, ByVal rowNum As Integer, ByVal bounds
          > As System.Drawing. Rectangle, ByVal [readOnly] As Boolean, ByVal instantText
          > As String, ByVal cellIsVisible As Boolean)
          >
          > MyBase.Edit(sou rce, rowNum, bounds, [readOnly], instantText, cellIsVisible)
          >
          > MyBase.TextBox. ForeColor = ForeColor()
          >
          > MyBase.TextBox. BackColor = BackColor
          >
          > End Sub
          >
          > Public Sub New()
          >
          > End Sub
          >
          > Private Sub dg_Scroll(ByVal sender As Object, ByVal e As System.EventArg s)
          > Handles dg.Scroll
          >
          > Trace.WriteLine ("Scroll")
          >
          > RedrawPanel()
          >
          > End Sub
          >
          > Private Sub MovePanel()
          >
          > mctrl.Location = New Point(dg.Left + dg.RowHeaderWid th + 2, dg.Top + 21)
          >
          > Dim intFactor As Integer = SystemInformati on.HorizontalSc rollBarHeight
          >
          > For Each ctrl As Control In Me.DataGridTabl eStyle.DataGrid .Controls
          >
          > If TypeOf ctrl Is HScrollBar Then
          >
          > If Not DirectCast(ctrl , HScrollBar).Vis ible Then intFactor = 0
          >
          > End If
          >
          > Next
          >
          > mctrl.Height = dg.Height - 21 - intFactor - 2
          >
          > End Sub
          >
          > Private Sub dg_Move(ByVal sender As Object, ByVal e As System.EventArg s)
          > Handles dg.Move
          >
          > MovePanel()
          >
          > End Sub
          >
          > Private Sub PreparePanel()
          >
          > Dim sf As New StringFormat
          >
          > sf.LineAlignmen t = StringAlignment .Center
          >
          > Dim rDraw As New RectangleF(0, 0, Me.Width, 20)
          >
          > Dim g As Graphics = mctrl.CreateGra phics
          >
          > g.Clear(mctrl.B ackColor)
          >
          > Try
          >
          > g.DrawString(Me .HeaderText, dg.Font, Brushes.Black, rDraw, sf)
          >
          > ControlPaint.Dr awBorder3D(g, _
          >
          > New Rectangle(0, 0, Me.Width, 19), Border3DStyle.R aisedInner)
          >
          > Catch
          >
          > End Try
          >
          > End Sub
          >
          > Private Sub dv_ListChanged( ByVal sender As Object, ByVal e As
          > System.Componen tModel.ListChan gedEventArgs)
          >
          > 'PreparePanel()
          >
          > RedrawPanel()
          >
          > End Sub
          >
          > Private Sub dg_VisibleChang ed(ByVal sender As Object, ByVal e As
          > System.EventArg s) Handles dg.VisibleChang ed
          >
          > Try
          >
          > mctrl.Visible = dg.Visible
          >
          > Catch ex As Exception
          >
          > End Try
          >
          > End Sub
          >
          > Private Sub dg_SizeChanged( ByVal sender As Object, ByVal e As
          > System.EventArg s) Handles dg.SizeChanged
          >
          > MovePanel()
          >
          > RedrawPanel()
          >
          > End Sub
          >
          > Private Sub RedrawPanel()
          >
          > Static oldTop As Integer = 0
          >
          > If Not mctrl Is Nothing And dg.VisibleRowCo unt > 0 Then
          >
          > Application.DoE vents()
          >
          > Dim hti As DataGrid.HitTes tInfo = dg.HitTest(pt)
          >
          > Dim newRow As Integer = hti.Row
          >
          > Trace.WriteLine (String.Format( "First Row {0} Visible rows {1}", hti.Row,
          > dg.VisibleRowCo unt))
          >
          > oldTop = newRow
          >
          > bPanelOnly = True
          >
          > For x As Integer = oldTop To oldTop + dg.VisibleRowCo unt - 1
          >
          > If x < cm.Count Then
          >
          > Trace.WriteLine (String.Format( "Drawing Row {0} {1}", x, dg.GetCellBound s(x,
          > dg.FirstVisible Column)))
          >
          > Paint(Nothing, dg.GetCellBound s(x, dg.FirstVisible Column), _
          >
          > cm, x, Nothing, Nothing, ar)
          >
          > End If
          >
          > Next
          >
          > bPanelOnly = False
          >
          > End If
          >
          > End Sub
          >
          > Private Sub dg_Resize(ByVal sender As Object, ByVal e As System.EventArg s)
          > Handles dg.Resize
          >
          > MovePanel()
          >
          > End Sub
          >
          > Private Sub mctrl_Paint(ByV al sender As Object, ByVal e As
          > System.Windows. Forms.PaintEven tArgs) Handles mctrl.Paint
          >
          > Dim sf As New StringFormat
          >
          > sf.LineAlignmen t = StringAlignment .Center
          >
          > Dim rDraw As New RectangleF(0, 0, Me.Width, 20)
          >
          > Dim g As Graphics = e.Graphics
          >
          > g.Clear(mctrl.B ackColor)
          >
          > Try
          >
          > g.DrawString(Me .HeaderText, dg.Font, Brushes.Black, rDraw, sf)
          >
          > ControlPaint.Dr awBorder3D(g, _
          >
          > New Rectangle(0, 0, Me.Width, 19), Border3DStyle.R aisedInner)
          >
          > Debug.WriteLine ("Panel Paint")
          >
          > Dim hti As DataGrid.HitTes tInfo = dg.HitTest(pt)
          >
          > Dim newRow As Integer = hti.Row
          >
          > Dim oldTop As Integer
          >
          > Trace.WriteLine (String.Format( "First Row {0} Visible rows {1}", hti.Row,
          > dg.VisibleRowCo unt))
          >
          > oldTop = newRow
          >
          > bPanelOnly = True
          >
          > For x As Integer = oldTop To oldTop + dg.VisibleRowCo unt - 1
          >
          > If x < cm.Count Then
          >
          > Trace.WriteLine (String.Format( "Drawing Row {0} {1}", x, dg.GetCellBound s(x,
          > dg.FirstVisible Column)))
          >
          > Paint(Nothing, dg.GetCellBound s(x, dg.FirstVisible Column), _
          >
          > cm, x, Nothing, Nothing, ar)
          >
          > End If
          >
          > Next
          >
          > Catch
          >
          > End Try
          >
          > End Sub
          >
          > Private Sub PaintRow(ByVal g As Graphics, ByVal bounds As Rectangle, ByVal
          > rownum As Integer)
          >
          > Dim brFore As Brush
          >
          > Dim brBack As Brush
          >
          > Dim cFore As Color
          >
          > Dim cBack As Color
          >
          > Dim bounds2 As New Rectangle(0, bounds.Y - 21, bounds.Width, bounds.Height)
          >
          > If Me.DataGridTabl eStyle.DataGrid .IsSelected(row num) Then
          >
          > cFore = Me.DataGridTabl eStyle.Selectio nForeColor
          >
          > cBack = Me.DataGridTabl eStyle.Selectio nBackColor
          >
          > Else
          >
          > cFore = ForeColor
          >
          > cBack = BackColor
          >
          > End If
          >
          > brBack = New LinearGradientB rush(bounds, cBack, Color.White, 90, False)
          >
          > brFore = New SolidBrush(cFor e)
          >
          >
          >
          > Dim bl As New Blend
          >
          > bl.Factors = New Single() {0.0F, 0.1F, 0.5F, 0.7F, 0.7F, 0.5F, 0.3F, 0.2F,
          > 0}
          >
          > bl.Positions = New Single() {0, 0.1F, 0.2F, 0.5F, 0.6F, 0.7F, 0.8F, 0.9F,
          > 1.0F}
          >
          > DirectCast(brBa ck, LinearGradientB rush).Blend = bl
          >
          > If mctrl.Width <> Me.Width Then mctrl.Width = Me.Width
          >
          > MyBase.Paint(g, bounds2, cm, rownum, _
          >
          > brBack, brFore, ar)
          >
          > If rownum = cm.Count - 1 Then
          >
          > Dim br As New SolidBrush(Me.D ataGridTableSty le.DataGrid.Bac kgroundColor)
          >
          > g.FillRectangle (br, 0, bounds2.Bottom + 1, mctrl.Width, _
          >
          > mctrl.Height - bounds2.Bottom - 1)
          >
          > End If
          >
          > End Sub
          >
          > End Class
          >
          >
          >
          > Ken
          >
          > -------------------------------
          >
          > "Agnes" <agnes@dynamict ech.com.hk> wrote in message
          > news:uCN6kFPwEH A.3012@TK2MSFTN GP10.phx.gbl...
          > I understand it is impossible, but still curious to know "Can I freeze
          > several column in the datagrid, the user can only scroll the first 3 columns
          > (not verical), for the rest of the coulumn, it is freeze.
          >
          >
          >
          >[/color]

          Comment

          • Marcie Jones

            #6
            Re: Freeze Column in DataGrid

            Hi James,
            For a web application you'd do this with client script:


            Marcie

            On Sat, 9 Apr 2005 23:41:01 -0700, "James"
            <KarmaJangchup@ community.nospa m> wrote:
            [color=blue]
            >I am looking for the same function in a web application (using a web form
            >data grid). The application uses C# and heaps of data grids that have the
            >first one or two columns populated with data that would be nice to have
            >remain visable as the user scrolls horizontally. Of course, it would also be
            >nice to have the headings remain visable as the user scrolls down the grid as
            >well.
            >
            >I had a quick look at Ken's code (although I am not a VB person), but it
            >seems the DataGridTextBox Column is only part of the Windows Form data grid.
            >So was wondering if anyone can give me any help with this.
            >
            >Cheers,
            >
            >"Ken Tucker [MVP]" wrote:
            >[color=green]
            >> Hi,
            >>
            >> Here is a column style that locks a column on the datagrid. It is
            >> still under development. basically if you set the locked property to true
            >> it places a panel over the datagrid that has the locked column drawn on it.
            >> Currently it only will lock the first column.
            >>
            >> Imports System.Drawing. Drawing2D
            >>
            >> Public Class ColoredGridColu mn
            >>
            >> Inherits DataGridTextBox Column
            >>
            >> Dim mForeColor As Color = Color.Black
            >>
            >> Dim mBackColor As Color = Color.White
            >>
            >> Dim WithEvents mctrl As DblBufferPanel
            >>
            >> Dim WithEvents dg As DataGrid
            >>
            >> Dim pt As New Point
            >>
            >> Dim bPanelOnly As Boolean = False
            >>
            >> Dim cm As CurrencyManager
            >>
            >> Dim ar As Boolean
            >>
            >> Private Class DblBufferPanel
            >>
            >> Inherits Panel
            >>
            >> Public Sub New()
            >>
            >> Me.SetStyle(Con trolStyles.Doub leBuffer, True)
            >>
            >> End Sub
            >>
            >> End Class
            >>
            >> Public Property ForeColor() As Color
            >>
            >> Get
            >>
            >> Return mForeColor
            >>
            >> End Get
            >>
            >> Set(ByVal Value As Color)
            >>
            >> mForeColor = Value
            >>
            >> End Set
            >>
            >> End Property
            >>
            >> Public Property BackColor() As Color
            >>
            >> Get
            >>
            >> Return mBackColor
            >>
            >> End Get
            >>
            >> Set(ByVal Value As Color)
            >>
            >> mBackColor = Value
            >>
            >> End Set
            >>
            >> End Property
            >>
            >> Public Property Locked() As Boolean
            >>
            >> Get
            >>
            >> Return Not mctrl Is Nothing
            >>
            >> End Get
            >>
            >> Set(ByVal Value As Boolean)
            >>
            >> If Value = False Then
            >>
            >> mctrl = Nothing
            >>
            >> Else
            >>
            >> mctrl = New DblBufferPanel
            >>
            >> End If
            >>
            >> End Set
            >>
            >> End Property
            >>
            >> Protected Overloads Overrides Sub Paint(ByVal g As System.Drawing. Graphics,
            >> ByVal bounds As System.Drawing. Rectangle, ByVal source As
            >> System.Windows. Forms.CurrencyM anager, ByVal rowNum As Integer, ByVal
            >> backBrush As System.Drawing. Brush, ByVal foreBrush As System.Drawing. Brush,
            >> ByVal alignToRight As Boolean)
            >>
            >> Dim brFore As Brush
            >>
            >> Dim brBack As Brush
            >>
            >> Dim cFore As Color
            >>
            >> Dim cBack As Color
            >>
            >> Static bPainted As Boolean = False
            >>
            >> If Not bPainted And Not (mctrl Is Nothing) Then
            >>
            >> dg = Me.DataGridTabl eStyle.DataGrid
            >>
            >> dg.Parent.Contr ols.Add(mctrl)
            >>
            >> MovePanel()
            >>
            >> mctrl.BringToFr ont()
            >>
            >> pt = dg.GetCellBound s(0, 0).Location
            >>
            >> If TypeOf dg.DataSource Is DataTable Then
            >>
            >> AddHandler DirectCast(dg.D ataSource, DataTable).Defa ultView.ListCha nged,
            >> AddressOf dv_ListChanged
            >>
            >> ElseIf TypeOf dg.DataSource Is DataView Then
            >>
            >> AddHandler DirectCast(dg.D ataSource, DataView).ListC hanged, AddressOf
            >> dv_ListChanged
            >>
            >> End If
            >>
            >> End If
            >>
            >> cm = source
            >>
            >> ar = alignToRight
            >>
            >> bPainted = True
            >>
            >> If Me.DataGridTabl eStyle.DataGrid .IsSelected(row Num) Then
            >>
            >> cFore = Me.DataGridTabl eStyle.Selectio nForeColor
            >>
            >> cBack = Me.DataGridTabl eStyle.Selectio nBackColor
            >>
            >> Else
            >>
            >> cFore = ForeColor
            >>
            >> cBack = BackColor
            >>
            >> End If
            >>
            >> brBack = New LinearGradientB rush(bounds, cBack, Color.White, 90, False)
            >>
            >> brFore = New SolidBrush(cFor e)
            >>
            >>
            >>
            >> Dim bl As New Blend
            >>
            >> bl.Factors = New Single() {0.0F, 0.1F, 0.5F, 0.7F, 0.7F, 0.5F, 0.3F, 0.2F,
            >> 0}
            >>
            >> bl.Positions = New Single() {0, 0.1F, 0.2F, 0.5F, 0.6F, 0.7F, 0.8F, 0.9F,
            >> 1.0F}
            >>
            >> DirectCast(brBa ck, LinearGradientB rush).Blend = bl
            >>
            >> If Not bPanelOnly Then
            >>
            >> MyBase.Paint(g, bounds, source, rowNum, brBack, brFore, alignToRight)
            >>
            >> End If
            >>
            >> If Not (mctrl Is Nothing) Then
            >>
            >> ' if there is another control to draw on move the bounds to the right edge
            >> if htere is not then it will ignore that directive right? yesgot oitf the
            >> control
            >>
            >> 'mctrl.Backgrou ndImage = bm
            >>
            >> PaintRow(mctrl. CreateGraphics, bounds, rowNum)
            >>
            >> End If
            >>
            >> If Me.GetColumnVal ueAtRow(source, rowNum).ToStrin g = "Davolio" Then
            >>
            >> Me.DataGridTabl eStyle.DataGrid .Select(rowNum)
            >>
            >> End If
            >>
            >> End Sub
            >>
            >> Public Shadows Sub BeginUpdate()
            >>
            >> MyBase.BeginUpd ate()
            >>
            >> End Sub
            >>
            >> Public Shadows Sub EndUpdate()
            >>
            >> MyBase.EndUpdat e()
            >>
            >> End Sub
            >>
            >> Protected Overloads Overrides Sub Edit(ByVal source As
            >> System.Windows. Forms.CurrencyM anager, ByVal rowNum As Integer, ByVal bounds
            >> As System.Drawing. Rectangle, ByVal [readOnly] As Boolean, ByVal instantText
            >> As String, ByVal cellIsVisible As Boolean)
            >>
            >> MyBase.Edit(sou rce, rowNum, bounds, [readOnly], instantText, cellIsVisible)
            >>
            >> MyBase.TextBox. ForeColor = ForeColor()
            >>
            >> MyBase.TextBox. BackColor = BackColor
            >>
            >> End Sub
            >>
            >> Public Sub New()
            >>
            >> End Sub
            >>
            >> Private Sub dg_Scroll(ByVal sender As Object, ByVal e As System.EventArg s)
            >> Handles dg.Scroll
            >>
            >> Trace.WriteLine ("Scroll")
            >>
            >> RedrawPanel()
            >>
            >> End Sub
            >>
            >> Private Sub MovePanel()
            >>
            >> mctrl.Location = New Point(dg.Left + dg.RowHeaderWid th + 2, dg.Top + 21)
            >>
            >> Dim intFactor As Integer = SystemInformati on.HorizontalSc rollBarHeight
            >>
            >> For Each ctrl As Control In Me.DataGridTabl eStyle.DataGrid .Controls
            >>
            >> If TypeOf ctrl Is HScrollBar Then
            >>
            >> If Not DirectCast(ctrl , HScrollBar).Vis ible Then intFactor = 0
            >>
            >> End If
            >>
            >> Next
            >>
            >> mctrl.Height = dg.Height - 21 - intFactor - 2
            >>
            >> End Sub
            >>
            >> Private Sub dg_Move(ByVal sender As Object, ByVal e As System.EventArg s)
            >> Handles dg.Move
            >>
            >> MovePanel()
            >>
            >> End Sub
            >>
            >> Private Sub PreparePanel()
            >>
            >> Dim sf As New StringFormat
            >>
            >> sf.LineAlignmen t = StringAlignment .Center
            >>
            >> Dim rDraw As New RectangleF(0, 0, Me.Width, 20)
            >>
            >> Dim g As Graphics = mctrl.CreateGra phics
            >>
            >> g.Clear(mctrl.B ackColor)
            >>
            >> Try
            >>
            >> g.DrawString(Me .HeaderText, dg.Font, Brushes.Black, rDraw, sf)
            >>
            >> ControlPaint.Dr awBorder3D(g, _
            >>
            >> New Rectangle(0, 0, Me.Width, 19), Border3DStyle.R aisedInner)
            >>
            >> Catch
            >>
            >> End Try
            >>
            >> End Sub
            >>
            >> Private Sub dv_ListChanged( ByVal sender As Object, ByVal e As
            >> System.Componen tModel.ListChan gedEventArgs)
            >>
            >> 'PreparePanel()
            >>
            >> RedrawPanel()
            >>
            >> End Sub
            >>
            >> Private Sub dg_VisibleChang ed(ByVal sender As Object, ByVal e As
            >> System.EventArg s) Handles dg.VisibleChang ed
            >>
            >> Try
            >>
            >> mctrl.Visible = dg.Visible
            >>
            >> Catch ex As Exception
            >>
            >> End Try
            >>
            >> End Sub
            >>
            >> Private Sub dg_SizeChanged( ByVal sender As Object, ByVal e As
            >> System.EventArg s) Handles dg.SizeChanged
            >>
            >> MovePanel()
            >>
            >> RedrawPanel()
            >>
            >> End Sub
            >>
            >> Private Sub RedrawPanel()
            >>
            >> Static oldTop As Integer = 0
            >>
            >> If Not mctrl Is Nothing And dg.VisibleRowCo unt > 0 Then
            >>
            >> Application.DoE vents()
            >>
            >> Dim hti As DataGrid.HitTes tInfo = dg.HitTest(pt)
            >>
            >> Dim newRow As Integer = hti.Row
            >>
            >> Trace.WriteLine (String.Format( "First Row {0} Visible rows {1}", hti.Row,
            >> dg.VisibleRowCo unt))
            >>
            >> oldTop = newRow
            >>
            >> bPanelOnly = True
            >>
            >> For x As Integer = oldTop To oldTop + dg.VisibleRowCo unt - 1
            >>
            >> If x < cm.Count Then
            >>
            >> Trace.WriteLine (String.Format( "Drawing Row {0} {1}", x, dg.GetCellBound s(x,
            >> dg.FirstVisible Column)))
            >>
            >> Paint(Nothing, dg.GetCellBound s(x, dg.FirstVisible Column), _
            >>
            >> cm, x, Nothing, Nothing, ar)
            >>
            >> End If
            >>
            >> Next
            >>
            >> bPanelOnly = False
            >>
            >> End If
            >>
            >> End Sub
            >>
            >> Private Sub dg_Resize(ByVal sender As Object, ByVal e As System.EventArg s)
            >> Handles dg.Resize
            >>
            >> MovePanel()
            >>
            >> End Sub
            >>
            >> Private Sub mctrl_Paint(ByV al sender As Object, ByVal e As
            >> System.Windows. Forms.PaintEven tArgs) Handles mctrl.Paint
            >>
            >> Dim sf As New StringFormat
            >>
            >> sf.LineAlignmen t = StringAlignment .Center
            >>
            >> Dim rDraw As New RectangleF(0, 0, Me.Width, 20)
            >>
            >> Dim g As Graphics = e.Graphics
            >>
            >> g.Clear(mctrl.B ackColor)
            >>
            >> Try
            >>
            >> g.DrawString(Me .HeaderText, dg.Font, Brushes.Black, rDraw, sf)
            >>
            >> ControlPaint.Dr awBorder3D(g, _
            >>
            >> New Rectangle(0, 0, Me.Width, 19), Border3DStyle.R aisedInner)
            >>
            >> Debug.WriteLine ("Panel Paint")
            >>
            >> Dim hti As DataGrid.HitTes tInfo = dg.HitTest(pt)
            >>
            >> Dim newRow As Integer = hti.Row
            >>
            >> Dim oldTop As Integer
            >>
            >> Trace.WriteLine (String.Format( "First Row {0} Visible rows {1}", hti.Row,
            >> dg.VisibleRowCo unt))
            >>
            >> oldTop = newRow
            >>
            >> bPanelOnly = True
            >>
            >> For x As Integer = oldTop To oldTop + dg.VisibleRowCo unt - 1
            >>
            >> If x < cm.Count Then
            >>
            >> Trace.WriteLine (String.Format( "Drawing Row {0} {1}", x, dg.GetCellBound s(x,
            >> dg.FirstVisible Column)))
            >>
            >> Paint(Nothing, dg.GetCellBound s(x, dg.FirstVisible Column), _
            >>
            >> cm, x, Nothing, Nothing, ar)
            >>
            >> End If
            >>
            >> Next
            >>
            >> Catch
            >>
            >> End Try
            >>
            >> End Sub
            >>
            >> Private Sub PaintRow(ByVal g As Graphics, ByVal bounds As Rectangle, ByVal
            >> rownum As Integer)
            >>
            >> Dim brFore As Brush
            >>
            >> Dim brBack As Brush
            >>
            >> Dim cFore As Color
            >>
            >> Dim cBack As Color
            >>
            >> Dim bounds2 As New Rectangle(0, bounds.Y - 21, bounds.Width, bounds.Height)
            >>
            >> If Me.DataGridTabl eStyle.DataGrid .IsSelected(row num) Then
            >>
            >> cFore = Me.DataGridTabl eStyle.Selectio nForeColor
            >>
            >> cBack = Me.DataGridTabl eStyle.Selectio nBackColor
            >>
            >> Else
            >>
            >> cFore = ForeColor
            >>
            >> cBack = BackColor
            >>
            >> End If
            >>
            >> brBack = New LinearGradientB rush(bounds, cBack, Color.White, 90, False)
            >>
            >> brFore = New SolidBrush(cFor e)
            >>
            >>
            >>
            >> Dim bl As New Blend
            >>
            >> bl.Factors = New Single() {0.0F, 0.1F, 0.5F, 0.7F, 0.7F, 0.5F, 0.3F, 0.2F,
            >> 0}
            >>
            >> bl.Positions = New Single() {0, 0.1F, 0.2F, 0.5F, 0.6F, 0.7F, 0.8F, 0.9F,
            >> 1.0F}
            >>
            >> DirectCast(brBa ck, LinearGradientB rush).Blend = bl
            >>
            >> If mctrl.Width <> Me.Width Then mctrl.Width = Me.Width
            >>
            >> MyBase.Paint(g, bounds2, cm, rownum, _
            >>
            >> brBack, brFore, ar)
            >>
            >> If rownum = cm.Count - 1 Then
            >>
            >> Dim br As New SolidBrush(Me.D ataGridTableSty le.DataGrid.Bac kgroundColor)
            >>
            >> g.FillRectangle (br, 0, bounds2.Bottom + 1, mctrl.Width, _
            >>
            >> mctrl.Height - bounds2.Bottom - 1)
            >>
            >> End If
            >>
            >> End Sub
            >>
            >> End Class
            >>
            >>
            >>
            >> Ken
            >>
            >> -------------------------------
            >>
            >> "Agnes" <agnes@dynamict ech.com.hk> wrote in message
            >> news:uCN6kFPwEH A.3012@TK2MSFTN GP10.phx.gbl...
            >> I understand it is impossible, but still curious to know "Can I freeze
            >> several column in the datagrid, the user can only scroll the first 3 columns
            >> (not verical), for the rest of the coulumn, it is freeze.
            >>
            >>
            >>
            >>[/color][/color]

            Comment

            • James

              #7
              Re: Freeze Column in DataGrid

              Thanks Marcie, I have had a look at the link and will try what it suggests
              today. Thank you for the kindness to take the time to reply and help.

              Cheers,
              Jamie (James)

              "Marcie Jones" wrote:
              [color=blue]
              > Hi James,
              > For a web application you'd do this with client script:
              > http://www.codeproject.com/aspnet/Fr...neDatagrid.asp
              >
              > Marcie
              >
              > On Sat, 9 Apr 2005 23:41:01 -0700, "James"
              > <KarmaJangchup@ community.nospa m> wrote:
              >[color=green]
              > >I am looking for the same function in a web application (using a web form
              > >data grid). The application uses C# and heaps of data grids that have the
              > >first one or two columns populated with data that would be nice to have
              > >remain visable as the user scrolls horizontally. Of course, it would also be
              > >nice to have the headings remain visable as the user scrolls down the grid as
              > >well.
              > >
              > >I had a quick look at Ken's code (although I am not a VB person), but it
              > >seems the DataGridTextBox Column is only part of the Windows Form data grid.
              > >So was wondering if anyone can give me any help with this.
              > >
              > >Cheers,
              > >
              > >"Ken Tucker [MVP]" wrote:
              > >[color=darkred]
              > >> Hi,
              > >>
              > >> Here is a column style that locks a column on the datagrid. It is
              > >> still under development. basically if you set the locked property to true
              > >> it places a panel over the datagrid that has the locked column drawn on it.
              > >> Currently it only will lock the first column.
              > >>
              > >> Imports System.Drawing. Drawing2D
              > >>
              > >> Public Class ColoredGridColu mn
              > >>
              > >> Inherits DataGridTextBox Column
              > >>
              > >> Dim mForeColor As Color = Color.Black
              > >>
              > >> Dim mBackColor As Color = Color.White
              > >>
              > >> Dim WithEvents mctrl As DblBufferPanel
              > >>
              > >> Dim WithEvents dg As DataGrid
              > >>
              > >> Dim pt As New Point
              > >>
              > >> Dim bPanelOnly As Boolean = False
              > >>
              > >> Dim cm As CurrencyManager
              > >>
              > >> Dim ar As Boolean
              > >>
              > >> Private Class DblBufferPanel
              > >>
              > >> Inherits Panel
              > >>
              > >> Public Sub New()
              > >>
              > >> Me.SetStyle(Con trolStyles.Doub leBuffer, True)
              > >>
              > >> End Sub
              > >>
              > >> End Class
              > >>
              > >> Public Property ForeColor() As Color
              > >>
              > >> Get
              > >>
              > >> Return mForeColor
              > >>
              > >> End Get
              > >>
              > >> Set(ByVal Value As Color)
              > >>
              > >> mForeColor = Value
              > >>
              > >> End Set
              > >>
              > >> End Property
              > >>
              > >> Public Property BackColor() As Color
              > >>
              > >> Get
              > >>
              > >> Return mBackColor
              > >>
              > >> End Get
              > >>
              > >> Set(ByVal Value As Color)
              > >>
              > >> mBackColor = Value
              > >>
              > >> End Set
              > >>
              > >> End Property
              > >>
              > >> Public Property Locked() As Boolean
              > >>
              > >> Get
              > >>
              > >> Return Not mctrl Is Nothing
              > >>
              > >> End Get
              > >>
              > >> Set(ByVal Value As Boolean)
              > >>
              > >> If Value = False Then
              > >>
              > >> mctrl = Nothing
              > >>
              > >> Else
              > >>
              > >> mctrl = New DblBufferPanel
              > >>
              > >> End If
              > >>
              > >> End Set
              > >>
              > >> End Property
              > >>
              > >> Protected Overloads Overrides Sub Paint(ByVal g As System.Drawing. Graphics,
              > >> ByVal bounds As System.Drawing. Rectangle, ByVal source As
              > >> System.Windows. Forms.CurrencyM anager, ByVal rowNum As Integer, ByVal
              > >> backBrush As System.Drawing. Brush, ByVal foreBrush As System.Drawing. Brush,
              > >> ByVal alignToRight As Boolean)
              > >>
              > >> Dim brFore As Brush
              > >>
              > >> Dim brBack As Brush
              > >>
              > >> Dim cFore As Color
              > >>
              > >> Dim cBack As Color
              > >>
              > >> Static bPainted As Boolean = False
              > >>
              > >> If Not bPainted And Not (mctrl Is Nothing) Then
              > >>
              > >> dg = Me.DataGridTabl eStyle.DataGrid
              > >>
              > >> dg.Parent.Contr ols.Add(mctrl)
              > >>
              > >> MovePanel()
              > >>
              > >> mctrl.BringToFr ont()
              > >>
              > >> pt = dg.GetCellBound s(0, 0).Location
              > >>
              > >> If TypeOf dg.DataSource Is DataTable Then
              > >>
              > >> AddHandler DirectCast(dg.D ataSource, DataTable).Defa ultView.ListCha nged,
              > >> AddressOf dv_ListChanged
              > >>
              > >> ElseIf TypeOf dg.DataSource Is DataView Then
              > >>
              > >> AddHandler DirectCast(dg.D ataSource, DataView).ListC hanged, AddressOf
              > >> dv_ListChanged
              > >>
              > >> End If
              > >>
              > >> End If
              > >>
              > >> cm = source
              > >>
              > >> ar = alignToRight
              > >>
              > >> bPainted = True
              > >>
              > >> If Me.DataGridTabl eStyle.DataGrid .IsSelected(row Num) Then
              > >>
              > >> cFore = Me.DataGridTabl eStyle.Selectio nForeColor
              > >>
              > >> cBack = Me.DataGridTabl eStyle.Selectio nBackColor
              > >>
              > >> Else
              > >>
              > >> cFore = ForeColor
              > >>
              > >> cBack = BackColor
              > >>
              > >> End If
              > >>
              > >> brBack = New LinearGradientB rush(bounds, cBack, Color.White, 90, False)
              > >>
              > >> brFore = New SolidBrush(cFor e)
              > >>
              > >>
              > >>
              > >> Dim bl As New Blend
              > >>
              > >> bl.Factors = New Single() {0.0F, 0.1F, 0.5F, 0.7F, 0.7F, 0.5F, 0.3F, 0.2F,
              > >> 0}
              > >>
              > >> bl.Positions = New Single() {0, 0.1F, 0.2F, 0.5F, 0.6F, 0.7F, 0.8F, 0.9F,
              > >> 1.0F}
              > >>
              > >> DirectCast(brBa ck, LinearGradientB rush).Blend = bl
              > >>
              > >> If Not bPanelOnly Then
              > >>
              > >> MyBase.Paint(g, bounds, source, rowNum, brBack, brFore, alignToRight)
              > >>
              > >> End If
              > >>
              > >> If Not (mctrl Is Nothing) Then
              > >>
              > >> ' if there is another control to draw on move the bounds to the right edge
              > >> if htere is not then it will ignore that directive right? yesgot oitf the
              > >> control
              > >>
              > >> 'mctrl.Backgrou ndImage = bm
              > >>
              > >> PaintRow(mctrl. CreateGraphics, bounds, rowNum)
              > >>
              > >> End If
              > >>
              > >> If Me.GetColumnVal ueAtRow(source, rowNum).ToStrin g = "Davolio" Then
              > >>
              > >> Me.DataGridTabl eStyle.DataGrid .Select(rowNum)
              > >>
              > >> End If
              > >>
              > >> End Sub
              > >>
              > >> Public Shadows Sub BeginUpdate()
              > >>
              > >> MyBase.BeginUpd ate()
              > >>
              > >> End Sub
              > >>
              > >> Public Shadows Sub EndUpdate()
              > >>
              > >> MyBase.EndUpdat e()
              > >>
              > >> End Sub
              > >>
              > >> Protected Overloads Overrides Sub Edit(ByVal source As
              > >> System.Windows. Forms.CurrencyM anager, ByVal rowNum As Integer, ByVal bounds
              > >> As System.Drawing. Rectangle, ByVal [readOnly] As Boolean, ByVal instantText
              > >> As String, ByVal cellIsVisible As Boolean)
              > >>
              > >> MyBase.Edit(sou rce, rowNum, bounds, [readOnly], instantText, cellIsVisible)
              > >>
              > >> MyBase.TextBox. ForeColor = ForeColor()
              > >>
              > >> MyBase.TextBox. BackColor = BackColor
              > >>
              > >> End Sub
              > >>
              > >> Public Sub New()
              > >>
              > >> End Sub
              > >>
              > >> Private Sub dg_Scroll(ByVal sender As Object, ByVal e As System.EventArg s)
              > >> Handles dg.Scroll
              > >>
              > >> Trace.WriteLine ("Scroll")
              > >>
              > >> RedrawPanel()
              > >>
              > >> End Sub
              > >>
              > >> Private Sub MovePanel()
              > >>
              > >> mctrl.Location = New Point(dg.Left + dg.RowHeaderWid th + 2, dg.Top + 21)
              > >>
              > >> Dim intFactor As Integer = SystemInformati on.HorizontalSc rollBarHeight
              > >>
              > >> For Each ctrl As Control In Me.DataGridTabl eStyle.DataGrid .Controls
              > >>
              > >> If TypeOf ctrl Is HScrollBar Then
              > >>
              > >> If Not DirectCast(ctrl , HScrollBar).Vis ible Then intFactor = 0
              > >>
              > >> End If
              > >>
              > >> Next
              > >>
              > >> mctrl.Height = dg.Height - 21 - intFactor - 2
              > >>
              > >> End Sub
              > >>
              > >> Private Sub dg_Move(ByVal sender As Object, ByVal e As System.EventArg s)
              > >> Handles dg.Move
              > >>
              > >> MovePanel()
              > >>
              > >> End Sub
              > >>
              > >> Private Sub PreparePanel()
              > >>
              > >> Dim sf As New StringFormat
              > >>
              > >> sf.LineAlignmen t = StringAlignment .Center
              > >>
              > >> Dim rDraw As New RectangleF(0, 0, Me.Width, 20)
              > >>
              > >> Dim g As Graphics = mctrl.CreateGra phics
              > >>
              > >> g.Clear(mctrl.B ackColor)
              > >>
              > >> Try
              > >>
              > >> g.DrawString(Me .HeaderText, dg.Font, Brushes.Black, rDraw, sf)
              > >>
              > >> ControlPaint.Dr awBorder3D(g, _
              > >>
              > >> New Rectangle(0, 0, Me.Width, 19), Border3DStyle.R aisedInner)
              > >>
              > >> Catch
              > >>
              > >> End Try
              > >>
              > >> End Sub
              > >>
              > >> Private Sub dv_ListChanged( ByVal sender As Object, ByVal e As
              > >> System.Componen tModel.ListChan gedEventArgs)
              > >>
              > >> 'PreparePanel()
              > >>
              > >> RedrawPanel()
              > >>
              > >> End Sub
              > >>
              > >> Private Sub dg_VisibleChang ed(ByVal sender As Object, ByVal e As
              > >> System.EventArg s) Handles dg.VisibleChang ed
              > >>
              > >> Try
              > >>
              > >> mctrl.Visible = dg.Visible
              > >>
              > >> Catch ex As Exception
              > >>
              > >> End Try
              > >>
              > >> End Sub
              > >>
              > >> Private Sub dg_SizeChanged( ByVal sender As Object, ByVal e As
              > >> System.EventArg s) Handles dg.SizeChanged
              > >>
              > >> MovePanel()
              > >>
              > >> RedrawPanel()
              > >>
              > >> End Sub
              > >>
              > >> Private Sub RedrawPanel()
              > >>
              > >> Static oldTop As Integer = 0
              > >>
              > >> If Not mctrl Is Nothing And dg.VisibleRowCo unt > 0 Then
              > >>
              > >> Application.DoE vents()
              > >>
              > >> Dim hti As DataGrid.HitTes tInfo = dg.HitTest(pt)
              > >>
              > >> Dim newRow As Integer = hti.Row
              > >>
              > >> Trace.WriteLine (String.Format( "First Row {0} Visible rows {1}", hti.Row,
              > >> dg.VisibleRowCo unt))
              > >>
              > >> oldTop = newRow
              > >>
              > >> bPanelOnly = True
              > >>
              > >> For x As Integer = oldTop To oldTop + dg.VisibleRowCo unt - 1
              > >>
              > >> If x < cm.Count Then
              > >>
              > >> Trace.WriteLine (String.Format( "Drawing Row {0} {1}", x, dg.GetCellBound s(x,
              > >> dg.FirstVisible Column)))
              > >>
              > >> Paint(Nothing, dg.GetCellBound s(x, dg.FirstVisible Column), _
              > >>
              > >> cm, x, Nothing, Nothing, ar)
              > >>
              > >> End If
              > >>
              > >> Next
              > >>
              > >> bPanelOnly = False
              > >>
              > >> End If
              > >>
              > >> End Sub
              > >>
              > >> Private Sub dg_Resize(ByVal sender As Object, ByVal e As System.EventArg s)
              > >> Handles dg.Resize
              > >>
              > >> MovePanel()
              > >>
              > >> End Sub
              > >>
              > >> Private Sub mctrl_Paint(ByV al sender As Object, ByVal e As
              > >> System.Windows. Forms.PaintEven tArgs) Handles mctrl.Paint
              > >>
              > >> Dim sf As New StringFormat
              > >>
              > >> sf.LineAlignmen t = StringAlignment .Center
              > >>
              > >> Dim rDraw As New RectangleF(0, 0, Me.Width, 20)
              > >>
              > >> Dim g As Graphics = e.Graphics
              > >>
              > >> g.Clear(mctrl.B ackColor)
              > >>
              > >> Try
              > >>
              > >> g.DrawString(Me .HeaderText, dg.Font, Brushes.Black, rDraw, sf)
              > >>
              > >> ControlPaint.Dr awBorder3D(g, _
              > >>
              > >> New Rectangle(0, 0, Me.Width, 19), Border3DStyle.R aisedInner)
              > >>
              > >> Debug.WriteLine ("Panel Paint")
              > >>
              > >> Dim hti As DataGrid.HitTes tInfo = dg.HitTest(pt)
              > >>
              > >> Dim newRow As Integer = hti.Row
              > >>
              > >> Dim oldTop As Integer
              > >>
              > >> Trace.WriteLine (String.Format( "First Row {0} Visible rows {1}", hti.Row,
              > >> dg.VisibleRowCo unt))
              > >>
              > >> oldTop = newRow
              > >>
              > >> bPanelOnly = True
              > >>
              > >> For x As Integer = oldTop To oldTop + dg.VisibleRowCo unt - 1
              > >>
              > >> If x < cm.Count Then
              > >>
              > >> Trace.WriteLine (String.Format( "Drawing Row {0} {1}", x, dg.GetCellBound s(x,
              > >> dg.FirstVisible Column)))
              > >>
              > >> Paint(Nothing, dg.GetCellBound s(x, dg.FirstVisible Column), _
              > >>
              > >> cm, x, Nothing, Nothing, ar)
              > >>
              > >> End If
              > >>
              > >> Next
              > >>
              > >> Catch
              > >>
              > >> End Try
              > >>
              > >> End Sub
              > >>
              > >> Private Sub PaintRow(ByVal g As Graphics, ByVal bounds As Rectangle, ByVal
              > >> rownum As Integer)
              > >>
              > >> Dim brFore As Brush
              > >>
              > >> Dim brBack As Brush
              > >>
              > >> Dim cFore As Color
              > >>
              > >> Dim cBack As Color
              > >>
              > >> Dim bounds2 As New Rectangle(0, bounds.Y - 21, bounds.Width, bounds.Height)
              > >>
              > >> If Me.DataGridTabl eStyle.DataGrid .IsSelected(row num) Then
              > >>
              > >> cFore = Me.DataGridTabl eStyle.Selectio nForeColor
              > >>
              > >> cBack = Me.DataGridTabl eStyle.Selectio nBackColor
              > >>
              > >> Else
              > >>
              > >> cFore = ForeColor
              > >>
              > >> cBack = BackColor
              > >>
              > >> End If
              > >>
              > >> brBack = New LinearGradientB rush(bounds, cBack, Color.White, 90, False)
              > >>
              > >> brFore = New SolidBrush(cFor e)
              > >>
              > >>
              > >>
              > >> Dim bl As New Blend
              > >>
              > >> bl.Factors = New Single() {0.0F, 0.1F, 0.5F, 0.7F, 0.7F, 0.5F, 0.3F, 0.2F,
              > >> 0}
              > >>
              > >> bl.Positions = New Single() {0, 0.1F, 0.2F, 0.5F, 0.6F, 0.7F, 0.8F, 0.9F,
              > >> 1.0F}
              > >>
              > >> DirectCast(brBa ck, LinearGradientB rush).Blend = bl
              > >>
              > >> If mctrl.Width <> Me.Width Then mctrl.Width = Me.Width
              > >>
              > >> MyBase.Paint(g, bounds2, cm, rownum, _
              > >>
              > >> brBack, brFore, ar)
              > >>
              > >> If rownum = cm.Count - 1 Then
              > >>
              > >> Dim br As New SolidBrush(Me.D ataGridTableSty le.DataGrid.Bac kgroundColor)
              > >>
              > >> g.FillRectangle (br, 0, bounds2.Bottom + 1, mctrl.Width, _
              > >>
              > >> mctrl.Height - bounds2.Bottom - 1)
              > >>
              > >> End If
              > >>
              > >> End Sub
              > >>
              > >> End Class
              > >>
              > >>
              > >>
              > >> Ken
              > >>
              > >> -------------------------------
              > >>
              > >> "Agnes" <agnes@dynamict ech.com.hk> wrote in message
              > >> news:uCN6kFPwEH A.3012@TK2MSFTN GP10.phx.gbl...
              > >> I understand it is impossible, but still curious to know "Can I freeze
              > >> several column in the datagrid, the user can only scroll the first 3 columns
              > >> (not verical), for the rest of the coulumn, it is freeze.
              > >>
              > >>
              > >>
              > >>[/color][/color]
              >
              >[/color]

              Comment

              Working...