i have a problem with the DataGridView when i fill it using a thread, sometimes it crashes and gives a Big Red Cross.
i bind it with a DataTable and fill the DataTable from the Database, and there is icon column in the DataGridView updated on CellFormatting event
i searched for this error online and found this solution:
public class DataGridViewPlus : DataGridView
/// This prevents the "red X" error which happens when you cause updates to a datagrid
/// from multiple threads. It catches the OnPaint() exception and invalidates
/// the grid so it gets redrawn the next time the application hits its message loop.
/// The following solution to this problem was found
/// at http://social.msdn.microsoft.com/forums/en-US/winforms/thread/fdd94896-80e9-4e91-9ed5-0348bf2633a9
protected override void OnPaint( PaintEventArgs e )
base.OnPaint( e );
i tried it but gives me this error instead
eption: index 0 does not have a value"
and this is my code:
If Not (UpdateThread Is Nothing) Then
If UpdateThread.IsAlive = True Then
If UpdateFlagOrdersDGV = False Then
UpdateFlagOrdersDGV = True
UpdateThread = New Thread(UpdateThreadStart)
UpdateThread.IsBackground = True
UpdateThread.Name = "UpdateThread"
UpdateFlagOrdersDGV = False