Browse Source

2009-08-24 Carlos Alberto Cortez <[email protected]>

	* DataGridTextBoxColumn.cs:
	* DataGrid.cs: Moving the cell to the add row (the last one) should
	not immediately add a new row - this should happen until the very
	first change happens in that textbox.
	Fixes part of #322974.


svn path=/trunk/mcs/; revision=140461
Carlos Alberto Cortez 16 years ago
parent
commit
c27e82555d

+ 8 - 0
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog

@@ -1,3 +1,11 @@
+2009-08-24  Carlos Alberto Cortez <[email protected]>
+
+	* DataGridTextBoxColumn.cs:
+	* DataGrid.cs: Moving the cell to the add row (the last one) should
+	not immediately add a new row - this should happen until the very
+	first change happens in that textbox.
+	Fixes part of #322974.
+
 2009-08-19  Carlos Alberto Cortez <[email protected]>
 
 	* ToolStripDropDown.cs: When assigning the owner item, use its Font as

+ 4 - 2
mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGrid.cs

@@ -266,6 +266,7 @@ namespace System.Windows.Forms
 		bool from_positionchanged_handler;
 
 		/* editing state */
+		internal bool pending_new_row;
 		bool cursor_in_add_row;
 		bool add_row_changed;
 		internal bool is_editing;		// Current cell is edit mode
@@ -544,10 +545,11 @@ namespace System.Windows.Forms
 				if (CurrentRow == RowsCount && ListManager.AllowNew) {
 					cursor_in_add_row = true;
 					add_row_changed = false;
-					AddNewRow ();
+					pending_new_row = true;
 				}
 				else {
 					cursor_in_add_row = false;
+					pending_new_row = false;
 				}
 
 				InvalidateRowHeader (old_row);
@@ -2542,7 +2544,7 @@ namespace System.Windows.Forms
 			CalcAreasAndInvalidate ();
 		}
 
-		private void AddNewRow ()
+		internal void AddNewRow ()
 		{
 			ListManager.EndCurrentEdit ();
 			ListManager.AddNew ();

+ 7 - 0
mcs/class/Managed.Windows.Forms/System.Windows.Forms/DataGridTextBoxColumn.cs

@@ -206,6 +206,13 @@ namespace System.Windows.Forms
 
 		void textbox_TextChanged (object o, EventArgs e)
 		{
+			// when the focus goes to the add row, the first TextChanged event
+			// should actually add the new row.
+			if (grid.pending_new_row) {
+				grid.pending_new_row = false;
+				grid.AddNewRow ();
+			}
+
 			textbox.IsInEditOrNavigateMode = false;
 		}