2009-01-09 Ivan N. Zlatev <contact@i-nz.net>
authorIvan Zlatev <ivan@ivanz.com>
Fri, 9 Jan 2009 19:03:02 +0000 (19:03 -0000)
committerIvan Zlatev <ivan@ivanz.com>
Fri, 9 Jan 2009 19:03:02 +0000 (19:03 -0000)
* DataGridView.cs: Track the Position in the CurrencyManager.

svn path=/trunk/mcs/; revision=122930

mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridView.cs

index 6addd5ba66d37364033fa9bc46852466b7062047..0d3f525648faa211cb826e2d791ad3d10a1e062a 100644 (file)
@@ -1,3 +1,7 @@
+2009-01-09  Ivan N. Zlatev  <contact@i-nz.net>
+
+       * DataGridView.cs: Track the Position in the CurrencyManager.
+
 2009-01-09  Ivan N. Zlatev  <contact@i-nz.net>
 
        * DataGridView.cs: Implement data-bound new item editing/addition.
index e830229f46739e72b27e356c0a65024609a19535..50ae2e4b0e810b58d0873dbd6fa2f5f62c95ffc1 100644 (file)
@@ -5475,7 +5475,8 @@ namespace System.Windows.Forms {
                }
 
                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) {
@@ -5852,8 +5853,10 @@ namespace System.Windows.Forms {
                        columns.ClearAutoGeneratedColumns ();
                        rows.Clear ();
                        PrepareEditingRow (false, true);
-                       if (DataManager != null)
+                       if (DataManager != null) {
                                DataManager.ListChanged -= OnListChanged;
+                               DataManager.PositionChanged -= OnListPositionChanged;
+                       }
                }
                
                private void DoBinding ()
@@ -5902,11 +5905,14 @@ namespace System.Windows.Forms {
                                        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 ();
                }
@@ -6033,6 +6039,14 @@ namespace System.Windows.Forms {
                        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 ()
                {