C#的DataGridView绑数据表
表被另外一条线程修改。我界面只要要显示这个表的数据,但是数据变动很频繁,而且界面的控件要根据数据表的内容,做一些变动。
请问如何绑定才保险?
我现在的办法是
微软封装的数据表:dataTableMain
绑定控件:bindingSourceMain
DataGridView:dataGridViewMain
bindingSourceMain.DataSource = dataTableMain;
dataGridViewMain.DataSource = bindingSourceMain;
dataTableMain.RowChanged += new DataRowChangeEventHandler(dataTableMain_RowChanged);
dataTableMain.RowDeleted += new DataRowChangeEventHandler(dataTableMain_RowChanged);
另外一条线程修改的是dataTableMain……
跑着跑着,经常会出现问题。而且错误停在程序入口处:Application.Run那
错误信息是:
BindingSource 不能是自己的数据源。请不要将 DataSource 和 DataMember 属性设置为循环引用 BindingSource 的值。
堆栈无显示
线程也无显示……杯具
未处理 System.InvalidOperationException
Message=BindingSource 不能是自己的数据源。请不要将 DataSource 和 DataMember 属性设置为循环引用 BindingSource 的值。
Source=System.Windows.Forms
StackTrace:
在 System.Windows.Forms.BindingSource.get_Count()
在 System.Windows.Forms.CurrencyManager.get_Count()
在 System.Windows.Forms.DataGridViewCell.GetValue(Int32 rowIndex)
在 System.Windows.Forms.DataGridViewTextBoxCell.GetPreferredSize(Graphics graphics, DataGridViewCellStyle cellStyle, Int32 rowIndex, Size constraintSize)
在 System.Windows.Forms.DataGridViewCell.GetPreferredWidth(Int32 rowIndex, Int32 height)
在 System.Windows.Forms.DataGridViewCell.OnCellDataAreaMouseEnterInternal(Int32 rowIndex)
在 System.Windows.Forms.DataGridViewCell.OnMouseMoveInternal(DataGridViewCellMouseEventArgs e)
在 System.Windows.Forms.DataGridView.OnCellMouseMove(DataGridViewCellMouseEventArgs e)
在 System.Windows.Forms.DataGridView.UpdateMouseEnteredCell(HitTestInfo hti, MouseEventArgs e)
在 System.Windows.Forms.DataGridView.OnMouseMove(MouseEventArgs e)
在 System.Windows.Forms.Control.WmMouseMove(Message& m)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.DataGridView.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.Run(Form mainForm)
在 LD.Future200.UI.Program.Main(String[] param) 位置 D:\shihao\workdir\07.Future200\04.Src\15.UI\Program.cs:行号 30
在 System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
InnerException: