DataGridView的全自动增加了新行

DataGridView的全自动增加了新行

本文介绍了DataGridView的全自动增加了新行 - 为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我使用的是Windows窗体一个旧的C#应用​​程序写得相当糟糕。最近,我不得不做出的一些应用广泛的变化,现在我面临相当奇怪的问题。

Hello I have an older C# application using Windows Forms was written quite poorly. I recently had to make some extensive changes in the app, and now I'm facing quite strange problem.

应用程序最初是设计用于装载在主窗口的OnLoad方法的数据(可怕的想法,我知道),后来重构将数据加载在另一个线程不显眼。该应用程序使用BindingListView(http://blw.sourceforge.net/),这是非常简单的实现IBindingListView接口的。

The application was first designed to load data in main windows OnLoad method (terrible idea, I know) and later refactored to load data in another thread unobtrusively. The application makes use of BindingListView (http://blw.sourceforge.net/) which is quite straightforward implementation of IBindingListView interface.

在我应用一切所做的更改工作的罚款。应用程序启动时加载的所有数据,有没有(等待程序加载数据时ommiting不好的用户体验)的任何问题。

Before the changes I made to application everything worked fine. Application started with all data loaded and there was not any problem (ommiting bad user experience when waiting for app to load data).

但是,当我改变了应用程序在另一个线程动态地加载数据(网格首先显示空,后来的数据加载到它),有开始流行了一些空行,这是不是在的ObservableCollection必然网格。

But when I changed the application to load data dynamicly in another thread (the grid is first displayed empty and later the data are loaded to it), there started to pop up some empty rows, which were not in the ObservableCollection bound to the grid.

我设法追踪新添加的行此调用堆栈:

I managed to track the new added rows to this call stack:

     Equin.ApplicationFramework.BindingListView.dll!Equin.ApplicationFramework.AggregateBindingListView<BusinessLogic.DataEntries.TrackEntry>.AddNew() Line 295 C#
    Equin.ApplicationFramework.BindingListView.dll!Equin.ApplicationFramework.AggregateBindingListView<BusinessLogic.DataEntries.TrackEntry>.System.ComponentModel.IBindingList.AddNew() Line 1617 + 0x8 bytes  C#
    System.Windows.Forms.dll!System.Windows.Forms.BindingSource.AddNew() + 0xbd bytes
    System.Windows.Forms.dll!System.Windows.Forms.CurrencyManager.AddNew() + 0x26 bytes
    System.Windows.Forms.dll!System.Windows.Forms.DataGridView.DataGridViewDataConnection.AddNew() + 0x86 bytes
    System.Windows.Forms.dll!System.Windows.Forms.DataGridView.DataGridViewDataConnection.OnNewRowNeeded() + 0x24 bytes
    System.Windows.Forms.dll!System.Windows.Forms.DataGridView.OnRowEnter(ref System.Windows.Forms.DataGridViewCell dataGridViewCell = null, int columnIndex = 0, int rowIndex = 0, bool canCreateNewRow, bool validationFailureOccurred) + 0x10a bytes
    System.Windows.Forms.dll!System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(int columnIndex = 0, int rowIndex = 0, bool setAnchorCellAddress, bool validateCurrentCell, bool throughMouseClick = false) + 0x59f bytes
    System.Windows.Forms.dll!System.Windows.Forms.DataGridView.SetAndSelectCurrentCellAddress(int columnIndex = 0, int rowIndex = 0, bool setAnchorCellAddress, bool validateCurrentCell, bool throughMouseClick, bool clearSelection = true, bool forceCurrentCellSelection = false) + 0x2a bytes
    System.Windows.Forms.dll!System.Windows.Forms.DataGridView.MakeFirstDisplayedCellCurrentCell(bool includeNewRow) + 0x66 bytes
    System.Windows.Forms.dll!System.Windows.Forms.DataGridView.OnEnter(System.EventArgs e) + 0xe0 bytes
    System.Windows.Forms.dll!System.Windows.Forms.Control.NotifyEnter() + 0x20 bytes
    System.Windows.Forms.dll!System.Windows.Forms.ContainerControl.UpdateFocusedControl() + 0xc6 bytes
    System.Windows.Forms.dll!System.Windows.Forms.ContainerControl.AssignActiveControlInternal(System.Windows.Forms.Control value = {System.Windows.Forms.DataGridView}) + 0x54 bytes
    System.Windows.Forms.dll!System.Windows.Forms.ContainerControl.ActivateControlInternal(System.Windows.Forms.Control control, bool originator = false) + 0x76 bytes
    System.Windows.Forms.dll!System.Windows.Forms.ContainerControl.SetActiveControlInternal(System.Windows.Forms.Control value = {System.Windows.Forms.DataGridView}) + 0x73 bytes
    System.Windows.Forms.dll!System.Windows.Forms.ContainerControl.SetActiveControl(System.Windows.Forms.Control ctl) + 0x33 bytes
    System.Windows.Forms.dll!System.Windows.Forms.ContainerControl.ActiveControl.set(System.Windows.Forms.Control value) + 0x5 bytes
    System.Windows.Forms.dll!System.Windows.Forms.Control.Select(bool directed, bool forward) + 0x1b bytes
    System.Windows.Forms.dll!System.Windows.Forms.Control.Select() + 0xf bytes
    System.Windows.Forms.dll!System.Windows.Forms.SplitContainer.SelectNextActiveControl(System.Windows.Forms.Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) + 0x2c bytes
    System.Windows.Forms.dll!System.Windows.Forms.SplitContainer.SelectNextControlInContainer(System.Windows.Forms.Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) + 0xdc bytes
    System.Windows.Forms.dll!System.Windows.Forms.SplitContainer.Select(bool directed, bool forward) + 0x65 bytes
    System.Windows.Forms.dll!System.Windows.Forms.Control.SelectNextControl(System.Windows.Forms.Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) + 0x7b bytes
    System.Windows.Forms.dll!System.Windows.Forms.Control.SelectNextControlInternal(System.Windows.Forms.Control ctl, bool forward, bool tabStopOnly, bool nested, bool wrap) + 0x4a bytes
    System.Windows.Forms.dll!System.Windows.Forms.Form.Active.set(bool value) + 0x11d bytes
    System.Windows.Forms.dll!System.Windows.Forms.Form.WmActivate(ref System.Windows.Forms.Message m) + 0x42 bytes
    System.Windows.Forms.dll!System.Windows.Forms.Form.WndProc(ref System.Windows.Forms.Message m) + 0x146 bytes
    System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.OnMessage(ref System.Windows.Forms.Message m) + 0x10 bytes
    System.Windows.Forms.dll!System.Windows.Forms.Control.ControlNativeWindow.WndProc(ref System.Windows.Forms.Message m) + 0x31 bytes
    System.Windows.Forms.dll!System.Windows.Forms.NativeWindow.Callback(System.IntPtr hWnd, int msg = 6, System.IntPtr wparam, System.IntPtr lparam) + 0x5a bytes
    [Native to Managed Transition]
    [Managed to Native Transition]
    System.Windows.Forms.dll!System.Windows.Forms.Control.SetVisibleCore(bool value = true) + 0x333 bytes
    System.Windows.Forms.dll!System.Windows.Forms.Form.SetVisibleCore(bool value = true) + 0x87 bytes
    System.Windows.Forms.dll!System.Windows.Forms.Control.Visible.set(bool value) + 0x11 bytes
    System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(int reason = -1, System.Windows.Forms.ApplicationContext context = {System.Windows.Forms.ApplicationContext}) + 0xe8 bytes
    System.Windows.Forms.dll!System.Windows.Forms.Application.ThreadContext.RunMessageLoop(int reason, System.Windows.Forms.ApplicationContext context) + 0x61 bytes
    System.Windows.Forms.dll!System.Windows.Forms.Application.Run(System.Windows.Forms.Form mainForm) + 0x31 bytes
    Registr optické komunikace.exe!GUI.Program.Main() Line 29 + 0x1d bytes  C#
    [Native to Managed Transition]
    [Managed to Native Transition]
    mscorlib.dll!System.AppDomain.nExecuteAssembly(System.Reflection.Assembly assembly, string[] args) + 0x19 bytes
    mscorlib.dll!System.Runtime.Hosting.ManifestRunner.Run(bool checkAptModel) + 0x6e bytes
    mscorlib.dll!System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly() + 0x84 bytes
    mscorlib.dll!System.Runtime.Hosting.ApplicationActivator.CreateInstance(System.ActivationContext activationContext, string[] activationCustomData) + 0x65 bytes
    mscorlib.dll!System.Runtime.Hosting.ApplicationActivator.CreateInstance(System.ActivationContext activationContext) + 0xa bytes
    mscorlib.dll!System.Activator.CreateInstance(System.ActivationContext activationContext) + 0x3e bytes
    Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone() + 0x23 bytes
    mscorlib.dll!System.Threading.ThreadHelper.ThreadStart_Context(object state) + 0x66 bytes
    mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x6f bytes
    mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() + 0x44 bytes

这让我怀疑,新的不必要的行的加入以某种方式在DataGridView中开始独自一人,没有明确的书面code做到这一点。

which makes me suspect, that the adding of the new unwanted row is somehow initiated in DataGridView alone, without explicitly written code to do it.

所以我的问题是 - 可以DataGridView中做到这一点?怎么可以把它关掉?我的下一个问题也是,我怎么可以跟踪什么烧制BindingListView的AddNew方法,如果在DataGridView只是处理发给它更早一些命令?

So my question is - can DataGridView do this? And how can it be turned off? My next question is also, how can I trace what is firing the AddNew method of BindingListView, if the DataGridView is just processing some commands issued to it earlier?

感谢您的任何想法...

Thanks for any ideas ...

对不起大家不写我的帖子够清楚了。

Sorry everyone for not writing my post clearly enough.

推荐答案

设置属性 AllowUserTAddRows = FALSE; 通过code或

Set the property AllowUserTAddRows=false; or through code

myDataGridView.AllowUserToAddRows = false;

这篇关于DataGridView的全自动增加了新行 - 为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 19:26