G
Guest
I m creating a multithreaded application in which a the datasource of a
datagridview is being updated from an other thread..
the following piece of code is here
private void UpdateGridView(DataSet ds)
{
try
{
DataSet nds = FlipDataSet(ds);
dataGridView1.DataSource = nds.Tables[0].DefaultView; //Exception
thrown when executing this statement. nds.Tables[0].DefaultView is not null
dataGridView1.Refresh();
}
catch
{
}
}
when the above portion of code executes, though it is inside the try catch
block, I get a NullReferenceException and here is the stack trace details
at System.Windows.Forms.DataGridViewRowHeaderCell.PaintPrivate(Graphics
graphics,
Rectangle clipBounds, Rectangle cellBounds, Int32 rowIndex,
DataGridViewElementStates
dataGridViewElementState, Object formattedValue, String errorText,
DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle
advancedBorderStyle,
DataGridViewPaintParts paintParts, Boolean computeContentBounds, Boolean
computeErrorIconBounds, Boolean paint)
at System.Windows.Forms.DataGridViewRowHeaderCell.Paint(Graphics
graphics,
Rectangle clipBounds, Rectangle cellBounds, Int32 rowIndex,
DataGridViewElementStates
cellState, Object value, Object formattedValue, String errorText,
DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle
advancedBorderStyle,
DataGridViewPaintParts paintParts)
at System.Windows.Forms.DataGridViewCell.PaintWork(Graphics graphics,
Rectangle
clipBounds, Rectangle cellBounds, Int32 rowIndex, DataGridViewElementStates
cellState, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle
advancedBorderStyle, DataGridViewPaintParts paintParts)
at System.Windows.Forms.DataGridViewRow.PaintHeader(Graphics graphics,
Rectangle
clipBounds, Rectangle rowBounds, Int32 rowIndex, DataGridViewElementStates
rowState,
Boolean isFirstDisplayedRow, Boolean isLastVisibleRow,
DataGridViewPaintParts
paintParts)
at System.Windows.Forms.DataGridViewRow.Paint(Graphics graphics,
Rectangle
clipBounds, Rectangle rowBounds, Int32 rowIndex, DataGridViewElementStates
rowState,
Boolean isFirstDisplayedRow, Boolean isLastVisibleRow)
at System.Windows.Forms.DataGridView.PaintRows(Graphics g, Rectangle
boundingRect,
Rectangle clipRect, Boolean singleHorizontalBorderAdded)
at System.Windows.Forms.DataGridView.PaintGrid(Graphics g, Rectangle
gridBounds,
Rectangle clipRect, Boolean singleVerticalBorderAdded, Boolean
singleHorizontalBorderAdded)
at System.Windows.Forms.DataGridView.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.DataGridView.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.DispatchMessageW(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMe
thods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32
reason, Int32
pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Scanner.Program.Main() in G:\UserDocs\Rajkiran's Documents
\Visual Studio 2008\Projects\Scanner
\Scanner\Program.cs:line 17
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext,
ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Please help me in resolving this.
datagridview is being updated from an other thread..
the following piece of code is here
private void UpdateGridView(DataSet ds)
{
try
{
DataSet nds = FlipDataSet(ds);
dataGridView1.DataSource = nds.Tables[0].DefaultView; //Exception
thrown when executing this statement. nds.Tables[0].DefaultView is not null
dataGridView1.Refresh();
}
catch
{
}
}
when the above portion of code executes, though it is inside the try catch
block, I get a NullReferenceException and here is the stack trace details
at System.Windows.Forms.DataGridViewRowHeaderCell.PaintPrivate(Graphics
graphics,
Rectangle clipBounds, Rectangle cellBounds, Int32 rowIndex,
DataGridViewElementStates
dataGridViewElementState, Object formattedValue, String errorText,
DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle
advancedBorderStyle,
DataGridViewPaintParts paintParts, Boolean computeContentBounds, Boolean
computeErrorIconBounds, Boolean paint)
at System.Windows.Forms.DataGridViewRowHeaderCell.Paint(Graphics
graphics,
Rectangle clipBounds, Rectangle cellBounds, Int32 rowIndex,
DataGridViewElementStates
cellState, Object value, Object formattedValue, String errorText,
DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle
advancedBorderStyle,
DataGridViewPaintParts paintParts)
at System.Windows.Forms.DataGridViewCell.PaintWork(Graphics graphics,
Rectangle
clipBounds, Rectangle cellBounds, Int32 rowIndex, DataGridViewElementStates
cellState, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle
advancedBorderStyle, DataGridViewPaintParts paintParts)
at System.Windows.Forms.DataGridViewRow.PaintHeader(Graphics graphics,
Rectangle
clipBounds, Rectangle rowBounds, Int32 rowIndex, DataGridViewElementStates
rowState,
Boolean isFirstDisplayedRow, Boolean isLastVisibleRow,
DataGridViewPaintParts
paintParts)
at System.Windows.Forms.DataGridViewRow.Paint(Graphics graphics,
Rectangle
clipBounds, Rectangle rowBounds, Int32 rowIndex, DataGridViewElementStates
rowState,
Boolean isFirstDisplayedRow, Boolean isLastVisibleRow)
at System.Windows.Forms.DataGridView.PaintRows(Graphics g, Rectangle
boundingRect,
Rectangle clipRect, Boolean singleHorizontalBorderAdded)
at System.Windows.Forms.DataGridView.PaintGrid(Graphics g, Rectangle
gridBounds,
Rectangle clipRect, Boolean singleVerticalBorderAdded, Boolean
singleHorizontalBorderAdded)
at System.Windows.Forms.DataGridView.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.DataGridView.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.DispatchMessageW(MSG& msg)
at
System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMe
thods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32
reason, Int32
pvLoopData)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Scanner.Program.Main() in G:\UserDocs\Rajkiran's Documents
\Visual Studio 2008\Projects\Scanner
\Scanner\Program.cs:line 17
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext,
ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
Please help me in resolving this.