This is a migrated thread and some comments may be shown as answers.

Red Crossed Recatngle after databinding

5 Answers 305 Views
GridView
This is a migrated thread and some comments may be shown as answers.
aleksandra stoeva
Top achievements
Rank 1
aleksandra stoeva asked on 06 Aug 2010, 08:16 PM
Hi Guys,

We seem to be unable to go around a problem on rebinding rad-grid, while moving columns. Please, advise.


We have a rad-grid, which constantly is being re-binded with the code below (the code below is running on the main thread). While this rebinding is going on, a person is reordering the columns, fast (don't know why they do it..) and at some point of time an exception is thrown and the rad-grid gets replaced by a red crossed rectangle. We cannot refresh or recover the grid - hence the user has no choice but to restart the program.
 
Private Sub ReBindMe()
        Dim ds As New DataSet
        Try
            If Not gridTasks.IsInEditMode Then
                If TypeOf gridTasks.DataSource Is DataSet And gridTasks.InvokeRequired = False Then
                    '--------------- ERROR HAPPENS ON THE LINE BELOW -------------------
                    CType(gridTasks.DataSource, DataSet).Tables("SELECT_TASKS").Clear()
                    CType(gridTasks.DataSource, DataSet).Tables("GetCheckListTriggeredLogDocList").Clear()
                    CType(gridTasks.DataSource, DataSet).Tables("GetCheckListTriggeredLogDocList").Merge(dt_GetCheckListTriggeredLogDocList)
                    CType(gridTasks.DataSource, DataSet).Tables("SELECT_TASKS").Merge(dt_Tasks)
                End If
            End If
        Catch ex As System.Exception
            'Throws error
        End Try
    End Sub
---------------------------------------------------------------------------------------------------------------------------
System Error Message:
Object reference not set to an instance of an object.
Stack trace:
   at Telerik.WinControls.RadElement.ComposeShouldPaintSystemSkin()
   at Telerik.WinControls.RadElement.ShouldPaintSystemSkin()
   at Telerik.WinControls.RadElement.Paint(IGraphics graphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.PaintOverride(IGraphics graphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.PaintChildren(IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.VisualElement.PaintChildren(IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.Paint(IGraphics graphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadItem.PaintOverride(IGraphics screenRadGraphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.UI.GridRowElement.PaintChildren(IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.Paint(IGraphics graphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadItem.PaintOverride(IGraphics screenRadGraphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.UI.GridTableBodyElement.PaintChildren(IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.Paint(IGraphics graphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadItem.PaintOverride(IGraphics screenRadGraphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.PaintChildren(IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.VisualElement.PaintChildren(IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.Paint(IGraphics graphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadItem.PaintOverride(IGraphics screenRadGraphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.PaintChildren(IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.VisualElement.PaintChildren(IGraphics graphics, Rectangle clipRectange, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadElement.Paint(IGraphics graphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RadItem.PaintOverride(IGraphics screenRadGraphics, Rectangle clipRectangle, Single angle, SizeF scale, Boolean useRelativeTransformation)
   at Telerik.WinControls.RootRadElement.Paint(IGraphics graphics, Rectangle clipRectangle)
   at Telerik.WinControls.RadControl.OnPaint(PaintEventArgs e)
   at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer, Boolean disposeEventArgs)
   at System.Windows.Forms.Control.WmPaint(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at Telerik.WinControls.RadControl.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at Telerik.WinControls.SafeNativeMethods.RedrawWindow(IntPtr hWnd, IntPtr rectUpdate, IntPtr hRgnUpdate, UInt32 uFlags)
   at Telerik.WinControls.UI.ThemedFormBehavior.RefreshNC()
   at Telerik.WinControls.UI.ThemedFormBehavior.OnWMNCActivate(Message& m)
   at Telerik.WinControls.UI.ThemedFormBehavior.HandleWndProc(Message& m)
   at Telerik.WinControls.UI.RadFormBehavior.HandleWndProc(Message& m)
   at Telerik.WinControls.UI.RadFormControlBase.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.IntDestroyWindow(HandleRef hWnd)
   at System.Windows.Forms.UnsafeNativeMethods.DestroyWindow(HandleRef hWnd)
   at System.Windows.Forms.NativeWindow.DestroyHandle()
   at System.Windows.Forms.Control.DestroyHandle()
   at System.Windows.Forms.Control.Dispose(Boolean disposing)
   at System.Windows.Forms.ContainerControl.Dispose(Boolean disposing)
   at System.Windows.Forms.Form.Dispose(Boolean disposing)
   at System.ComponentModel.Component.Dispose()
   at Telerik.WinControls.UI.GridHeaderCellElement.DisposeManagedResources()
   at Telerik.WinControls.DisposableObject.PerformDispose(Boolean disposing)
   at Telerik.WinControls.RadElement.PerformDispose(Boolean disposing)
   at Telerik.WinControls.DisposableObject.Dispose(Boolean disposing)
   at Telerik.WinControls.RadElement.DisposeChildren()
   at Telerik.WinControls.RadElement.PerformDispose(Boolean disposing)
   at Telerik.WinControls.DisposableObject.Dispose(Boolean disposing)
   at Telerik.WinControls.RadElement.DisposeChildren()
   at Telerik.WinControls.UI.GridTableBodyElement.CleanupRows()
   at Telerik.WinControls.UI.GridTableElement.Update_Reset(GridUINotifyAction action, GridViewRowInfo[] rowInfos)
   at Telerik.WinControls.UI.GridTableElement.UpdateCore(GridUINotifyAction action, GridViewRowInfo[] rowInfos)
   at Telerik.WinControls.UI.GridTableElement.Update(GridUINotifyAction action, GridViewRowInfo[] rowInfos)
   at Telerik.WinControls.UI.GridViewTemplate.UpdateUI(GridUINotifyAction action, GridViewRowInfo[] rowInfos)
   at Telerik.WinControls.Data.DataAccessComponent.UpdateAll(GridUINotifyAction action, GridViewRowInfo[] rowInfos)
   at Telerik.WinControls.UI.GridViewTemplate.Update(GridUINotifyAction action)
   at Telerik.WinControls.Data.DataAccessComponent.InitDataGrid()
   at Telerik.WinControls.Data.DataAccessComponent.currencyManager_ListChanged(Object sender, ListChangedEventArgs e)
   at System.Windows.Forms.CurrencyManager.OnListChanged(ListChangedEventArgs e)
   at System.Windows.Forms.CurrencyManager.List_ListChanged(Object sender, ListChangedEventArgs e)
   at System.Data.DataView.OnListChanged(ListChangedEventArgs e)
   at System.Data.DataView.IndexListChanged(Object sender, ListChangedEventArgs e)
   at System.Data.DataView.IndexListChangedInternal(ListChangedEventArgs e)
   at System.Data.DataViewListener.IndexListChanged(ListChangedEventArgs e)
   at System.Data.Index.<OnListChanged>b__2(DataViewListener listener, ListChangedEventArgs args, Boolean arg2, Boolean arg3)
   at System.Data.Listeners`1.Notify[T1,T2,T3](T1 arg1, T2 arg2, T3 arg3, Action`4 action)
   at System.Data.Index.OnListChanged(ListChangedEventArgs e)
   at System.Data.Index.FireResetEvent()
   at System.Data.Index.Reset()
   at System.Data.DataTable.ResetInternalIndexes(DataColumn column)
   at System.Data.DataTable.Clear(Boolean clearAll)
   at System.Data.DataTable.Clear()
   at ...................................................... line ...x

5 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 07 Aug 2010, 07:24 AM
Hello Aleksandra,

First thing you could try is setting the data source for the grid to null and set it back again but this will revert the grid to it's original state, if you are saying that columns are moving around i think it would be better to save the layout of the grid and after rebinding load the previous layout.

Hope this helps,
Emanuel Varga
0
aleksandra stoeva
Top achievements
Rank 1
answered on 09 Aug 2010, 02:59 PM
Hi Emanual,

Thank you for you reply. I did try to set the DataSource to Nothing before rebinding. Then the same thing happens on the line I set the DataSource to Nothing (Nothing in VB is equivalent to null in C#).

Basically if I try to touch the datasource in any way, whether setting it to null, or clearing, or merging rows in the underlying tables, the error happens. As to the columns - they are being moved by the user, the error always happens after the ColumnIndexchanged event (I print out when the methods get hit).
What do you mean by saving the layout and reloading it? Do you mean not to let the ColunmnIndexChanging event happen, just record it, and swap the columns manually when I call the method for binding?
0
Svett
Telerik team
answered on 11 Aug 2010, 02:28 PM
Hello aleksandra stoeva,

It is not appropriate to rebind the grid while you are reordering columns of RadGridView instance. Can you give more details how you bind the grid and what are you doing in ColumnIndexChanging event handler? What are the steps that we have to follow to experience the issue?

Regards,
Svett
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
aleksandra stoeva
Top achievements
Rank 1
answered on 11 Aug 2010, 03:08 PM
Hi Svett,

We have a timer triggering every 2 seconds - calling the ReBindMe method I have provided at the top of this thread. The ReBindMe method runs on the main thread. Users do stuff to the grid meanwhile. One of them insisted on playing with reordering the columns, very fast and if you are persistent enough always happens what I explained above.
Just to make sure that the reordering of the columns does not happen somehow in the midle of the rebinding I made the code print when it reaches and exits ColumnIndexChanging, ColumnIndexChanged, ReBindMe (there is no other code in ColimnIndexChanging and CoilumnIndex changed but a print statement). The events always occur consequentially.
0
Julian Benkov
Telerik team
answered on 16 Aug 2010, 07:52 PM
Hi Aleksandra Stoeva,

Thanks for writing.

Our RadGridView does not support such functionality. Please note reordering columns and rebinding the RadGridView instance every 2 seconds can bring the control to an invalid state. You can prevent the user from making changes in the columns collection and start/stop rebinding in columns reorder operation, but this will not guarantee that the RadGridView control will stay in a valid state. 


Please consider the following sample code:

Public Partial Class Form1
    Inherits Form
    Private table As New DataTable("TableName")
    Private timer As New Timer()
 
    Public Sub New()
        InitializeComponent()
 
        timer.Interval = 2000
        timer.Start()
        timer.Tick += New EventHandler(AddressOf timer_Tick)
        Me.radGridView1.ColumnIndexChanging += New ColumnIndexChangingEventHandler(AddressOf radGridView1_ColumnIndexChanging)
        Me.radGridView1.ColumnIndexChanged += New ColumnIndexChangedEventHandler(AddressOf radGridView1_ColumnIndexChanged)
    End Sub
 
    Private Sub radGridView1_ColumnIndexChanged(sender As Object, e As ColumnIndexChangedEventArgs)
        Me.timer.Start()
    End Sub
 
    Private Sub radGridView1_ColumnIndexChanging(sender As Object, e As ColumnIndexChangingEventArgs)
        Me.timer.[Stop]()
    End Sub
 
    Private Sub timer_Tick(sender As Object, e As EventArgs)
        Me.radGridView1.AllowColumnReorder = False
 
        Me.radGridView1.DataSource = Nothing
        Me.radGridView1.DataSource = table
 
        Me.radGridView1.AllowColumnReorder = True
    End Sub
 
    Protected Overrides Sub OnLoad(e As EventArgs)
        MyBase.OnLoad(e)
 
        table.Columns.Add("Id", GetType(Integer))
        table.Columns.Add("City", GetType(String))
        table.Columns.Add("Country", GetType(String))
 
        table.Rows.Add(0, "Sofia", "Bulgaria")
        table.Rows.Add(1, "London", "UK")
    End Sub
End Class

I hope this helps. Let me know if you have further queries.

All the best,
Julian Benkov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
aleksandra stoeva
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
aleksandra stoeva
Top achievements
Rank 1
Svett
Telerik team
Julian Benkov
Telerik team
Share this question
or