C # DataGridView (IndexOutOfRangeException) (операция недопустима, поскольку она приводит к повторному вызову функции SetCurrentCellAddressCore) - PullRequest
1 голос
/ 06 мая 2019

Мой исходный код, вызвавший проблему:

dataGridView1.DataSource = new BindingSource().DataSource = myDataSourceVar;

И это исправили, изменив его на:

BindingSource myBindingSource = new BindingSource();
myBindingSource.DataSource = myDataSourceVar;
dataGridView1.DataSource = myBindingSource ;

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

Список ошибок:

************** Exception Text **************
System.IndexOutOfRangeException: Index -1 does not have a value.
   at System.Windows.Forms.CurrencyManager.get_Item(Int32 index)
   at System.Windows.Forms.DataGridView.DataGridViewDataConnection.OnRowEnter(DataGridViewCellEventArgs e)
   at System.Windows.Forms.DataGridView.OnRowEnter(DataGridViewCell& dataGridViewCell, Int32 columnIndex, Int32 rowIndex, Boolean canCreateNewRow, Boolean validationFailureOccurred)
   at System.Windows.Forms.DataGridView.SetCurrentCellAddressCore(Int32 columnIndex, Int32 rowIndex, Boolean setAnchorCellAddress, Boolean validateCurrentCell, Boolean throughMouseClick)
   at System.Windows.Forms.DataGridView.OnCellMouseDown(HitTestInfo hti, Boolean isShiftDown, Boolean isControlDown)
   at System.Windows.Forms.DataGridView.OnCellMouseDown(DataGridViewCellMouseEventArgs e)
   at System.Windows.Forms.DataGridView.OnMouseDown(MouseEventArgs e)
   at System.Windows.Forms.Control.WmMouseDown(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.DataGridView.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
System.IndexOutOfRangeException: 'Index -1 does not have a value.
operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function.

Другие ссылки:

  1. Исключение для приложения Windows Form
  2. Проблема привязки данных к объекту DataGridView «Индекс -1 не имеет значения»
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...