Datagrid ScrollBar always visible: StackOverflowException

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all.
I build a new class for DataGrid control adding an handler to always show a
Vertical ScrollBar in the grid. The code is below.

----------------------------------------------
Public Class MyDataGrid
Inherits DataGrid

Private _imgList As ImageList
Public Event CurrentRowChanged()
Private oldSelectedRow As Integer = -1

Public Sub New()
AddHandler MyBase.VertScrollBar.VisibleChanged, AddressOf ShowScrollBars
MyBase.VertScrollBar.Visible = True
End Sub 'New

Private Sub ShowScrollBars(ByVal sender As Object, ByVal e As EventArgs)
If Not MyBase.VertScrollBar.Visible Then
Dim width As Integer = MyBase.VertScrollBar.Width
MyBase.VertScrollBar.Location = New
Point(MyBase.ClientRectangle.Width - width - 2, 2)
MyBase.VertScrollBar.Size = New Size(width,
MyBase.ClientRectangle.Height - 4)
MyBase.VertScrollBar.Show() [****]
End If
End Sub

end class
----------------------------------------------------

It runs well: adding new rows to the grid (programmatically) updates/resizes
the VScrollBar automatically showing the VScrollBar since the beginning,
even if there are a few rows in the grid. Adding new rows, simply updates
the VScrollBar (through the Sub above) and all it's OK.

The problem is when I use a TabControl. I put the datagrid on a TabPage and
click for creating new rows staying on the "2nd TabPage": this operation
causes a StackOverflowException while executing the line [****].

Uhmm... I don't know absolutely what's the real problem. Can anyone help me?

Many thanks
Francesco
 
Back
Top