DataGridView автоматически добавляет новую строку - почему?

Здравствуйте, у меня более старое приложение C #, использующее Windows Forms, было написано довольно плохо. Недавно мне пришлось внести в приложение серьезные изменения, и теперь я столкнулся с довольно странной проблемой.

Приложение было сначала разработано для загрузки данных в главном окне методом OnLoad (ужасная идея, я знаю), а позже было проведено рефакторинг для ненавязчивой загрузки данных в другом потоке. Приложение использует BindingListView ( http://blw.sourceforge.net/ ), который является довольно простой реализацией интерфейса IBindingListView.

До внесения изменений в приложение все работало нормально. Приложение запустилось со всеми загруженными данными, и никаких проблем не было (исключение неудовлетворительного взаимодействия с пользователем при ожидании загрузки данных приложением).

Но когда я изменил приложение для динамической загрузки данных в другом потоке (сетка сначала отображается пустой, а затем в нее загружаются данные), начали появляться некоторые пустые строки, которых не было в ObservableCollection, привязанном к сетки.

Мне удалось отследить новые добавленные строки в этот стек вызовов:

     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, без явно написанного кода для этого.

У меня вопрос - может ли DataGridView это сделать? А как его отключить? Мой следующий вопрос также заключается в том, как я могу отследить, что запускает метод AddNew BindingListView, если DataGridView просто обрабатывает некоторые команды, выданные ему ранее?

6
задан Cœur 16 April 2017 в 03:56
поделиться