}
internal void SetSelectedRowCoreInternal (int rowIndex, bool selected) {
- SetSelectedRowCore (rowIndex, selected);
+ if (rowIndex >= 0 && rowIndex < Rows.Count)
+ SetSelectedRowCore (rowIndex, selected);
}
protected virtual void SetSelectedRowCore (int rowIndex, bool selected) {
columns.ClearAutoGeneratedColumns ();
rows.Clear ();
PrepareEditingRow (false, true);
- if (DataManager != null)
+ if (DataManager != null) {
DataManager.ListChanged -= OnListChanged;
+ DataManager.PositionChanged -= OnListPositionChanged;
+ }
}
private void DoBinding ()
AddBoundRow (element);
DataManager.ListChanged += OnListChanged;
+ DataManager.PositionChanged += OnListPositionChanged;
OnDataBindingComplete (new DataGridViewBindingCompleteEventArgs (ListChangedType.Reset));
+ OnListPositionChanged (this, EventArgs.Empty);
+ } else {
+ if (Rows.Count > 0 && Columns.Count > 0)
+ MoveCurrentCell (0, 0, true, false, false, false);
}
- if (Rows.Count > 0 && Columns.Count > 0)
- MoveCurrentCell (0, 0, true, false, false, false);
PerformLayout();
Invalidate ();
}
Invalidate ();
}
+ private void OnListPositionChanged (object sender, EventArgs args)
+ {
+ if (Rows.Count > 0 && Columns.Count > 0)
+ MoveCurrentCell (DataManager.Position == -1 ? -1 : 0, DataManager.Position,
+ true, false, false, true);
+ else
+ MoveCurrentCell (-1, -1, true, false, false, true);
+ }
private void ReBind ()
{