|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Re: Freeze Column in DataGriddata 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 DataGridTextBoxColumn is only part of the Windows Form data grid. So was wondering if anyone can give me any help with this. Cheers, Show quoteHide quote "Ken Tucker [MVP]" wrote: > 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 ColoredGridColumn > > Inherits DataGridTextBoxColumn > > 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(ControlStyles.DoubleBuffer, 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.CurrencyManager, 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.DataGridTableStyle.DataGrid > > dg.Parent.Controls.Add(mctrl) > > MovePanel() > > mctrl.BringToFront() > > pt = dg.GetCellBounds(0, 0).Location > > If TypeOf dg.DataSource Is DataTable Then > > AddHandler DirectCast(dg.DataSource, DataTable).DefaultView.ListChanged, > AddressOf dv_ListChanged > > ElseIf TypeOf dg.DataSource Is DataView Then > > AddHandler DirectCast(dg.DataSource, DataView).ListChanged, AddressOf > dv_ListChanged > > End If > > End If > > cm = source > > ar = alignToRight > > bPainted = True > > If Me.DataGridTableStyle.DataGrid.IsSelected(rowNum) Then > > cFore = Me.DataGridTableStyle.SelectionForeColor > > cBack = Me.DataGridTableStyle.SelectionBackColor > > Else > > cFore = ForeColor > > cBack = BackColor > > End If > > brBack = New LinearGradientBrush(bounds, cBack, Color.White, 90, False) > > brFore = New SolidBrush(cFore) > > > > 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(brBack, LinearGradientBrush).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.BackgroundImage = bm > > PaintRow(mctrl.CreateGraphics, bounds, rowNum) > > End If > > If Me.GetColumnValueAtRow(source, rowNum).ToString = "Davolio" Then > > Me.DataGridTableStyle.DataGrid.Select(rowNum) > > End If > > End Sub > > Public Shadows Sub BeginUpdate() > > MyBase.BeginUpdate() > > End Sub > > Public Shadows Sub EndUpdate() > > MyBase.EndUpdate() > > End Sub > > Protected Overloads Overrides Sub Edit(ByVal source As > System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal bounds > As System.Drawing.Rectangle, ByVal [readOnly] As Boolean, ByVal instantText > As String, ByVal cellIsVisible As Boolean) > > MyBase.Edit(source, 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.EventArgs) > Handles dg.Scroll > > Trace.WriteLine("Scroll") > > RedrawPanel() > > End Sub > > Private Sub MovePanel() > > mctrl.Location = New Point(dg.Left + dg.RowHeaderWidth + 2, dg.Top + 21) > > Dim intFactor As Integer = SystemInformation.HorizontalScrollBarHeight > > For Each ctrl As Control In Me.DataGridTableStyle.DataGrid.Controls > > If TypeOf ctrl Is HScrollBar Then > > If Not DirectCast(ctrl, HScrollBar).Visible 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.EventArgs) > Handles dg.Move > > MovePanel() > > End Sub > > Private Sub PreparePanel() > > Dim sf As New StringFormat > > sf.LineAlignment = StringAlignment.Center > > Dim rDraw As New RectangleF(0, 0, Me.Width, 20) > > Dim g As Graphics = mctrl.CreateGraphics > > g.Clear(mctrl.BackColor) > > Try > > g.DrawString(Me.HeaderText, dg.Font, Brushes.Black, rDraw, sf) > > ControlPaint.DrawBorder3D(g, _ > > New Rectangle(0, 0, Me.Width, 19), Border3DStyle.RaisedInner) > > Catch > > End Try > > End Sub > > Private Sub dv_ListChanged(ByVal sender As Object, ByVal e As > System.ComponentModel.ListChangedEventArgs) > > 'PreparePanel() > > RedrawPanel() > > End Sub > > Private Sub dg_VisibleChanged(ByVal sender As Object, ByVal e As > System.EventArgs) Handles dg.VisibleChanged > > 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.EventArgs) Handles dg.SizeChanged > > MovePanel() > > RedrawPanel() > > End Sub > > Private Sub RedrawPanel() > > Static oldTop As Integer = 0 > > If Not mctrl Is Nothing And dg.VisibleRowCount > 0 Then > > Application.DoEvents() > > Dim hti As DataGrid.HitTestInfo = dg.HitTest(pt) > > Dim newRow As Integer = hti.Row > > Trace.WriteLine(String.Format("First Row {0} Visible rows {1}", hti.Row, > dg.VisibleRowCount)) > > oldTop = newRow > > bPanelOnly = True > > For x As Integer = oldTop To oldTop + dg.VisibleRowCount - 1 > > If x < cm.Count Then > > Trace.WriteLine(String.Format("Drawing Row {0} {1}", x, dg.GetCellBounds(x, > dg.FirstVisibleColumn))) > > Paint(Nothing, dg.GetCellBounds(x, dg.FirstVisibleColumn), _ > > 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.EventArgs) > Handles dg.Resize > > MovePanel() > > End Sub > > Private Sub mctrl_Paint(ByVal sender As Object, ByVal e As > System.Windows.Forms.PaintEventArgs) Handles mctrl.Paint > > Dim sf As New StringFormat > > sf.LineAlignment = StringAlignment.Center > > Dim rDraw As New RectangleF(0, 0, Me.Width, 20) > > Dim g As Graphics = e.Graphics > > g.Clear(mctrl.BackColor) > > Try > > g.DrawString(Me.HeaderText, dg.Font, Brushes.Black, rDraw, sf) > > ControlPaint.DrawBorder3D(g, _ > > New Rectangle(0, 0, Me.Width, 19), Border3DStyle.RaisedInner) > > Debug.WriteLine("Panel Paint") > > Dim hti As DataGrid.HitTestInfo = 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.VisibleRowCount)) > > oldTop = newRow > > bPanelOnly = True > > For x As Integer = oldTop To oldTop + dg.VisibleRowCount - 1 > > If x < cm.Count Then > > Trace.WriteLine(String.Format("Drawing Row {0} {1}", x, dg.GetCellBounds(x, > dg.FirstVisibleColumn))) > > Paint(Nothing, dg.GetCellBounds(x, dg.FirstVisibleColumn), _ > > 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.DataGridTableStyle.DataGrid.IsSelected(rownum) Then > > cFore = Me.DataGridTableStyle.SelectionForeColor > > cBack = Me.DataGridTableStyle.SelectionBackColor > > Else > > cFore = ForeColor > > cBack = BackColor > > End If > > brBack = New LinearGradientBrush(bounds, cBack, Color.White, 90, False) > > brFore = New SolidBrush(cFore) > > > > 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(brBack, LinearGradientBrush).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.DataGridTableStyle.DataGrid.BackgroundColor) > > g.FillRectangle(br, 0, bounds2.Bottom + 1, mctrl.Width, _ > > mctrl.Height - bounds2.Bottom - 1) > > End If > > End Sub > > End Class > > > > Ken > > ------------------------------- > > "Agnes" <ag***@dynamictech.com.hk> wrote in message > news:uCN6kFPwEHA.3012@TK2MSFTNGP10.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. > > > > Hi James,
For a web application you'd do this with client script: http://www.codeproject.com/aspnet/FreezePaneDatagrid.asp Marcie On Sat, 9 Apr 2005 23:41:01 -0700, "James" <KarmaJangchup@community.nospam> wrote: Show quoteHide quote >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 DataGridTextBoxColumn 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: > >> 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 ColoredGridColumn >> >> Inherits DataGridTextBoxColumn >> >> 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(ControlStyles.DoubleBuffer, 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.CurrencyManager, 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.DataGridTableStyle.DataGrid >> >> dg.Parent.Controls.Add(mctrl) >> >> MovePanel() >> >> mctrl.BringToFront() >> >> pt = dg.GetCellBounds(0, 0).Location >> >> If TypeOf dg.DataSource Is DataTable Then >> >> AddHandler DirectCast(dg.DataSource, DataTable).DefaultView.ListChanged, >> AddressOf dv_ListChanged >> >> ElseIf TypeOf dg.DataSource Is DataView Then >> >> AddHandler DirectCast(dg.DataSource, DataView).ListChanged, AddressOf >> dv_ListChanged >> >> End If >> >> End If >> >> cm = source >> >> ar = alignToRight >> >> bPainted = True >> >> If Me.DataGridTableStyle.DataGrid.IsSelected(rowNum) Then >> >> cFore = Me.DataGridTableStyle.SelectionForeColor >> >> cBack = Me.DataGridTableStyle.SelectionBackColor >> >> Else >> >> cFore = ForeColor >> >> cBack = BackColor >> >> End If >> >> brBack = New LinearGradientBrush(bounds, cBack, Color.White, 90, False) >> >> brFore = New SolidBrush(cFore) >> >> >> >> 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(brBack, LinearGradientBrush).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.BackgroundImage = bm >> >> PaintRow(mctrl.CreateGraphics, bounds, rowNum) >> >> End If >> >> If Me.GetColumnValueAtRow(source, rowNum).ToString = "Davolio" Then >> >> Me.DataGridTableStyle.DataGrid.Select(rowNum) >> >> End If >> >> End Sub >> >> Public Shadows Sub BeginUpdate() >> >> MyBase.BeginUpdate() >> >> End Sub >> >> Public Shadows Sub EndUpdate() >> >> MyBase.EndUpdate() >> >> End Sub >> >> Protected Overloads Overrides Sub Edit(ByVal source As >> System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal bounds >> As System.Drawing.Rectangle, ByVal [readOnly] As Boolean, ByVal instantText >> As String, ByVal cellIsVisible As Boolean) >> >> MyBase.Edit(source, 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.EventArgs) >> Handles dg.Scroll >> >> Trace.WriteLine("Scroll") >> >> RedrawPanel() >> >> End Sub >> >> Private Sub MovePanel() >> >> mctrl.Location = New Point(dg.Left + dg.RowHeaderWidth + 2, dg.Top + 21) >> >> Dim intFactor As Integer = SystemInformation.HorizontalScrollBarHeight >> >> For Each ctrl As Control In Me.DataGridTableStyle.DataGrid.Controls >> >> If TypeOf ctrl Is HScrollBar Then >> >> If Not DirectCast(ctrl, HScrollBar).Visible 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.EventArgs) >> Handles dg.Move >> >> MovePanel() >> >> End Sub >> >> Private Sub PreparePanel() >> >> Dim sf As New StringFormat >> >> sf.LineAlignment = StringAlignment.Center >> >> Dim rDraw As New RectangleF(0, 0, Me.Width, 20) >> >> Dim g As Graphics = mctrl.CreateGraphics >> >> g.Clear(mctrl.BackColor) >> >> Try >> >> g.DrawString(Me.HeaderText, dg.Font, Brushes.Black, rDraw, sf) >> >> ControlPaint.DrawBorder3D(g, _ >> >> New Rectangle(0, 0, Me.Width, 19), Border3DStyle.RaisedInner) >> >> Catch >> >> End Try >> >> End Sub >> >> Private Sub dv_ListChanged(ByVal sender As Object, ByVal e As >> System.ComponentModel.ListChangedEventArgs) >> >> 'PreparePanel() >> >> RedrawPanel() >> >> End Sub >> >> Private Sub dg_VisibleChanged(ByVal sender As Object, ByVal e As >> System.EventArgs) Handles dg.VisibleChanged >> >> 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.EventArgs) Handles dg.SizeChanged >> >> MovePanel() >> >> RedrawPanel() >> >> End Sub >> >> Private Sub RedrawPanel() >> >> Static oldTop As Integer = 0 >> >> If Not mctrl Is Nothing And dg.VisibleRowCount > 0 Then >> >> Application.DoEvents() >> >> Dim hti As DataGrid.HitTestInfo = dg.HitTest(pt) >> >> Dim newRow As Integer = hti.Row >> >> Trace.WriteLine(String.Format("First Row {0} Visible rows {1}", hti.Row, >> dg.VisibleRowCount)) >> >> oldTop = newRow >> >> bPanelOnly = True >> >> For x As Integer = oldTop To oldTop + dg.VisibleRowCount - 1 >> >> If x < cm.Count Then >> >> Trace.WriteLine(String.Format("Drawing Row {0} {1}", x, dg.GetCellBounds(x, >> dg.FirstVisibleColumn))) >> >> Paint(Nothing, dg.GetCellBounds(x, dg.FirstVisibleColumn), _ >> >> 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.EventArgs) >> Handles dg.Resize >> >> MovePanel() >> >> End Sub >> >> Private Sub mctrl_Paint(ByVal sender As Object, ByVal e As >> System.Windows.Forms.PaintEventArgs) Handles mctrl.Paint >> >> Dim sf As New StringFormat >> >> sf.LineAlignment = StringAlignment.Center >> >> Dim rDraw As New RectangleF(0, 0, Me.Width, 20) >> >> Dim g As Graphics = e.Graphics >> >> g.Clear(mctrl.BackColor) >> >> Try >> >> g.DrawString(Me.HeaderText, dg.Font, Brushes.Black, rDraw, sf) >> >> ControlPaint.DrawBorder3D(g, _ >> >> New Rectangle(0, 0, Me.Width, 19), Border3DStyle.RaisedInner) >> >> Debug.WriteLine("Panel Paint") >> >> Dim hti As DataGrid.HitTestInfo = 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.VisibleRowCount)) >> >> oldTop = newRow >> >> bPanelOnly = True >> >> For x As Integer = oldTop To oldTop + dg.VisibleRowCount - 1 >> >> If x < cm.Count Then >> >> Trace.WriteLine(String.Format("Drawing Row {0} {1}", x, dg.GetCellBounds(x, >> dg.FirstVisibleColumn))) >> >> Paint(Nothing, dg.GetCellBounds(x, dg.FirstVisibleColumn), _ >> >> 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.DataGridTableStyle.DataGrid.IsSelected(rownum) Then >> >> cFore = Me.DataGridTableStyle.SelectionForeColor >> >> cBack = Me.DataGridTableStyle.SelectionBackColor >> >> Else >> >> cFore = ForeColor >> >> cBack = BackColor >> >> End If >> >> brBack = New LinearGradientBrush(bounds, cBack, Color.White, 90, False) >> >> brFore = New SolidBrush(cFore) >> >> >> >> 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(brBack, LinearGradientBrush).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.DataGridTableStyle.DataGrid.BackgroundColor) >> >> g.FillRectangle(br, 0, bounds2.Bottom + 1, mctrl.Width, _ >> >> mctrl.Height - bounds2.Bottom - 1) >> >> End If >> >> End Sub >> >> End Class >> >> >> >> Ken >> >> ------------------------------- >> >> "Agnes" <ag***@dynamictech.com.hk> wrote in message >> news:uCN6kFPwEHA.3012@TK2MSFTNGP10.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. >> >> >> >> Sure, if I *had* a Try Catch block. But sometimes (and keep this one
just between us :)) I write code that isn't wrapped in a Try. Shocking, I know. My present technique - the one which wastes time - is that when I *do* get an unexpected exception, I then end execution, wrap the relevant bit in a Try, then run again and follow the same code path to get to that place, only this time I am waiting to Catch the exception. I was hoping I could avoid having to make myself habitually put everything in a Try block. I've changed coding practice in the past, so it's possible - but I'd rather be able to just access the exception that's made me break execution. Phil wrote: Show quoteHide quote > Larry, > > Sorry if I miss your point here. Can you not use the Try Catch block, and > have it show you the exception? > > ie. > > Try > Dim a As Integer = 1 > Dim b As Integer = 0 > Dim c As Integer = a \ b > Catch ex as exception > msgbox(ex.message) > End Try > > Rgds, > > Phil > > "Larry Lard" <larryl***@hotmail.com> wrote in message > news:1122572937.797232.81900@g43g2000cwa.googlegroups.com... > > I'm hoping there's a way to do this, because my present technique > > wastes a lot of time. > > > > Suppose I have this console app: > > > > Module Module1 > > > > Sub Main() > > Dim a As Integer = 1 > > Dim b As Integer = 0 > > Dim c As Integer = a \ b > > End Sub > > > > End Module > > > > When I run this from within the IDE, obviously execution will halt with > > a divide by zero exception when attempting to assign to c. The > > dialogbox presented to me tells me the exception type, and 'Additional > > information' which is in fact the exception's Message property. The > > buttons I can click are Break and Continue. If I click Continue, > > execution ends, which is fine. > > > > If I click Break, I am now in debug mode in the IDE and can I have the > > command line and all the usual debug tools, so I can (in this example) > > examine b and see that it is indeed zero, and understand why I got my > > exception. > > > > However. In a more real-world example, some of the information that > > would help debug would be *in the Exception that has just been thrown*. > > My question therefore is: > > > > Once I have clicked Break and entered debug mode, is there any way to > > obtain / interrogate / anything! the Exception which got me here? > > > > -- > > Larry Lard > > Replies to group please > > 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) Show quoteHide quote "Marcie Jones" wrote: > Hi James, > For a web application you'd do this with client script: > http://www.codeproject.com/aspnet/FreezePaneDatagrid.asp > > Marcie > > On Sat, 9 Apr 2005 23:41:01 -0700, "James" > <KarmaJangchup@community.nospam> wrote: > > >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 DataGridTextBoxColumn 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: > > > >> 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 ColoredGridColumn > >> > >> Inherits DataGridTextBoxColumn > >> > >> 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(ControlStyles.DoubleBuffer, 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.CurrencyManager, 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.DataGridTableStyle.DataGrid > >> > >> dg.Parent.Controls.Add(mctrl) > >> > >> MovePanel() > >> > >> mctrl.BringToFront() > >> > >> pt = dg.GetCellBounds(0, 0).Location > >> > >> If TypeOf dg.DataSource Is DataTable Then > >> > >> AddHandler DirectCast(dg.DataSource, DataTable).DefaultView.ListChanged, > >> AddressOf dv_ListChanged > >> > >> ElseIf TypeOf dg.DataSource Is DataView Then > >> > >> AddHandler DirectCast(dg.DataSource, DataView).ListChanged, AddressOf > >> dv_ListChanged > >> > >> End If > >> > >> End If > >> > >> cm = source > >> > >> ar = alignToRight > >> > >> bPainted = True > >> > >> If Me.DataGridTableStyle.DataGrid.IsSelected(rowNum) Then > >> > >> cFore = Me.DataGridTableStyle.SelectionForeColor > >> > >> cBack = Me.DataGridTableStyle.SelectionBackColor > >> > >> Else > >> > >> cFore = ForeColor > >> > >> cBack = BackColor > >> > >> End If > >> > >> brBack = New LinearGradientBrush(bounds, cBack, Color.White, 90, False) > >> > >> brFore = New SolidBrush(cFore) > >> > >> > >> > >> 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(brBack, LinearGradientBrush).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.BackgroundImage = bm > >> > >> PaintRow(mctrl.CreateGraphics, bounds, rowNum) > >> > >> End If > >> > >> If Me.GetColumnValueAtRow(source, rowNum).ToString = "Davolio" Then > >> > >> Me.DataGridTableStyle.DataGrid.Select(rowNum) > >> > >> End If > >> > >> End Sub > >> > >> Public Shadows Sub BeginUpdate() > >> > >> MyBase.BeginUpdate() > >> > >> End Sub > >> > >> Public Shadows Sub EndUpdate() > >> > >> MyBase.EndUpdate() > >> > >> End Sub > >> > >> Protected Overloads Overrides Sub Edit(ByVal source As > >> System.Windows.Forms.CurrencyManager, ByVal rowNum As Integer, ByVal bounds > >> As System.Drawing.Rectangle, ByVal [readOnly] As Boolean, ByVal instantText > >> As String, ByVal cellIsVisible As Boolean) > >> > >> MyBase.Edit(source, 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.EventArgs) > >> Handles dg.Scroll > >> > >> Trace.WriteLine("Scroll") > >> > >> RedrawPanel() > >> > >> End Sub > >> > >> Private Sub MovePanel() > >> > >> mctrl.Location = New Point(dg.Left + dg.RowHeaderWidth + 2, dg.Top + 21) > >> > >> Dim intFactor As Integer = SystemInformation.HorizontalScrollBarHeight > >> > >> For Each ctrl As Control In Me.DataGridTableStyle.DataGrid.Controls > >> > >> If TypeOf ctrl Is HScrollBar Then > >> > >> If Not DirectCast(ctrl, HScrollBar).Visible 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.EventArgs) > >> Handles dg.Move > >> > >> MovePanel() > >> > >> End Sub > >> > >> Private Sub PreparePanel() > >> > >> Dim sf As New StringFormat > >> > >> sf.LineAlignment = StringAlignment.Center > >> > >> Dim rDraw As New RectangleF(0, 0, Me.Width, 20) > >> > >> Dim g As Graphics = mctrl.CreateGraphics > >> > >> g.Clear(mctrl.BackColor) > >> > >> Try > >> > >> g.DrawString(Me.HeaderText, dg.Font, Brushes.Black, rDraw, sf) > >> > >> ControlPaint.DrawBorder3D(g, _ > >> > >> New Rectangle(0, 0, Me.Width, 19), Border3DStyle.RaisedInner) > >> > >> Catch > >> > >> End Try > >> > >> End Sub > >> > >> Private Sub dv_ListChanged(ByVal sender As Object, ByVal e As > >> System.ComponentModel.ListChangedEventArgs) > >> > >> 'PreparePanel() > >> > >> RedrawPanel() > >> > >> End Sub > >> > >> Private Sub dg_VisibleChanged(ByVal sender As Object, ByVal e As > >> System.EventArgs) Handles dg.VisibleChanged > >> > >> 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.EventArgs) Handles dg.SizeChanged > >> > >> MovePanel() > >> > >> RedrawPanel() > >> > >> End Sub > >> > >> Private Sub RedrawPanel() > >> > >> Static oldTop As Integer = 0 > >> > >> If Not mctrl Is Nothing And dg.VisibleRowCount > 0 Then > >> > >> Application.DoEvents() > >> > >> Dim hti As DataGrid.HitTestInfo = dg.HitTest(pt) > >> > >> Dim newRow As Integer = hti.Row > >> > >> Trace.WriteLine(String.Format("First Row {0} Visible rows {1}", hti.Row, > >> dg.VisibleRowCount)) > >> > >> oldTop = newRow > >> > >> bPanelOnly = True > >> > >> For x As Integer = oldTop To oldTop + dg.VisibleRowCount - 1 > >> > >> If x < cm.Count Then > >> > >> Trace.WriteLine(String.Format("Drawing Row {0} {1}", x, dg.GetCellBounds(x, > >> dg.FirstVisibleColumn))) > >> > >> Paint(Nothing, dg.GetCellBounds(x, dg.FirstVisibleColumn), _ > >> > >> 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.EventArgs) > >> Handles dg.Resize > >> > >> MovePanel() > >> > >> End Sub > >> > >> Private Sub mctrl_Paint(ByVal sender As Object, ByVal e As > >> System.Windows.Forms.PaintEventArgs) Handles mctrl.Paint > >> > >> Dim sf As New StringFormat > >> > >> sf.LineAlignment = StringAlignment.Center > >> > >> Dim rDraw As New RectangleF(0, 0, Me.Width, 20) > >> > >> Dim g As Graphics = e.Graphics > >> > >> g.Clear(mctrl.BackColor) > >> > >> Try > >> > >> g.DrawString(Me.HeaderText, dg.Font, Brushes.Black, rDraw, sf) > >> > >> ControlPaint.DrawBorder3D(g, _ > >> > >> New Rectangle(0, 0, Me.Width, 19), Border3DStyle.RaisedInner) > >> > >> Debug.WriteLine("Panel Paint") > >> > >> Dim hti As DataGrid.HitTestInfo = 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.VisibleRowCount)) > >> > >> oldTop = newRow > >> > >> bPanelOnly = True > >> > >> For x As Integer = oldTop To oldTop + dg.VisibleRowCount - 1 > >> > >> If x < cm.Count Then > >> > >> Trace.WriteLine(String.Format("Drawing Row {0} {1}", x, dg.GetCellBounds(x, > >> dg.FirstVisibleColumn))) > >> > >> Paint(Nothing, dg.GetCellBounds(x, dg.FirstVisibleColumn), _ > >> > >> 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.DataGridTableStyle.DataGrid.IsSelected(rownum) Then > >> > >> cFore = Me.DataGridTableStyle.SelectionForeColor > >> > >> cBack = Me.DataGridTableStyle.SelectionBackColor > >> > >> Else > >> > >> cFore = ForeColor > >> > >> cBack = BackColor > >> > >> End If > >> > >> brBack = New LinearGradientBrush(bounds, cBack, Color.White, 90, False) > >> > >> brFore = New SolidBrush(cFore) > >> > >> > >> > >> 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(brBack, LinearGradientBrush).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.DataGridTableStyle.DataGrid.BackgroundColor) > >> > >> g.FillRectangle(br, 0, bounds2.Bottom + 1, mctrl.Width, _ > >> > >> mctrl.Height - bounds2.Bottom - 1) > >> > >> End If > >> > >> End Sub > >> > >> End Class > >> > >> > >> > >> Ken > >> > >> ------------------------------- > >> > >> "Agnes" <ag***@dynamictech.com.hk> wrote in message > >> news:uCN6kFPwEHA.3012@TK2MSFTNGP10.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. > >> > >> > >> > >> > >
Visual Basic.net
Access vs SQL How can I let the internet explorer start to navigate in the same windwo? How to catch a right-click Multi-dimensional array with variable number of elements in last dimension Legacy Client <--> DotNet Listener TAB (key) to next control instead of next column (in datagrid) Writing to Web Server Unable to start debuging on the web server Getting reference to an ErrorProvider |
|||||||||||||||||||||||