VB.NET : Datagrid's scrolling giving error after selecting row-VBForums
Results 1 to 1 of 1

Thread: VB.NET : Datagrid's scrolling giving error after selecting row

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2011
    Posts
    5

    VB.NET : Datagrid's scrolling giving error after selecting row

    When I am scrolling datagrid after selecting one row I am getting error as "An unhandled exception of type 'System.StackOverflowException' occurred in System.Windows.Forms.dll" on line :

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

    Please find the attachment.

    Whole code is given below :



    ' Hosts a TextBox control in a cell of a DataGridColumnStyle for editing strings.
    '
    ' Note:
    ' Adds the ability to change the color of an individual cell. As each row in the column is
    ' painted an event is fired that allows the setting of the new color.

    ' Added returning the cell value when it's being painted. Also if the row is selected the
    ' selection colors will be used.
    '-----------------------------------------------------------------------------------------------'

    ' Additional namespaces.
    Imports System.Windows.Forms
    Imports System.Drawing

    Public Class FormatableCellDataGridTextBoxColumn

    ' Base class.
    Inherits DataGridTextBoxColumn

    ' Delegates.
    Public Delegate Sub PaintingCellEventHandler( _
    ByVal sender As Object, _
    ByVal e As PaintingCellEventArgs)
    Public Delegate Sub EditingCellEventHandler( _
    ByVal sender As Object, _
    ByVal e As EditingCellEventArgs)

    ' Events.
    Public Event PaintingCell As PaintingCellEventHandler
    Public Event EditingCell As EditingCellEventHandler

    ' Instance variables.
    Private _columnNum As Integer

    Public Sub New(ByVal columnNum As Integer)


    ' Initialize instance variables.
    _columnNum = columnNum

    End Sub

    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)


    ' Local variables.
    Dim foreColor As Color
    Dim backColor As Color
    Dim rowIsSelected As Boolean = False
    Dim text As String = NullText
    Dim value As Object = GetColumnValueAtRow(source, rowNum)
    Dim arg As PaintingCellEventArgs

    ' Determine if the row is selected.
    If TypeOf foreBrush Is SolidBrush AndAlso TypeOf backBrush Is SolidBrush Then
    foreColor = DirectCast(foreBrush, SolidBrush).Color
    backColor = DirectCast(backBrush, SolidBrush).Color
    If _
    foreColor.Equals(DataGridTableStyle.SelectionForeColor) AndAlso _
    backColor.Equals(DataGridTableStyle.SelectionBackColor) Then
    rowIsSelected = True
    End If
    End If

    ' Retrieve brushes.
    If Not IsDBNull(value) Then text = value.ToString()
    arg = New PaintingCellEventArgs( _
    rowNum, _
    _columnNum, _
    text, _
    backBrush, _
    foreBrush)
    If Not rowIsSelected Then RaiseEvent PaintingCell(Me, arg)

    ' Paint the cell.
    MyBase.Paint(g, bounds, source, rowNum, arg.BackBrush, arg.ForeBrush, alignToRight)

    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)

    ' Local variables.
    Dim editBoxIsToBeHidden As Boolean = False
    Dim e As New EditingCellEventArgs(rowNum, _columnNum, editBoxIsToBeHidden)

    ' Retrieve edit instructions.
    RaiseEvent EditingCell(Me, e)

    ' Allow the call to progress normally.

    MyBase.Edit( _
    source, _
    rowNum, _
    bounds, _
    [readOnly], _
    instantText, _
    cellIsVisible)

    ' Hide the edit box.
    If e.EditBoxIsToBeHidden Then
    Me.HideEditBox()
    End If

    End Sub

    End Class
    Attached Images Attached Images  

Tags for this Thread

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.