1 // Permission is hereby granted, free of charge, to any person obtaining 2 // a copy of this software and associated documentation files (the 3 // "Software"), to deal in the Software without restriction, including 4 // without limitation the rights to use, copy, modify, merge, publish, 5 // distribute, sublicense, and/or sell copies of the Software, and to 6 // permit persons to whom the Software is furnished to do so, subject to 7 // the following conditions: 8 // 9 // The above copyright notice and this permission notice shall be 10 // included in all copies or substantial portions of the Software. 11 // 12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 // 20 // Copyright (c) 2005 Novell, Inc. (http://www.novell.com) 21 // 22 // Author: 23 // Jordi Mas i Hernandez <jordi@ximian.com> 24 // 25 // 26 27 using System; 28 using System.Collections; 29 using System.ComponentModel; 30 using System.Drawing; 31 using System.Windows.Forms; 32 using System.Xml; 33 using NUnit.Framework; 34 using System.Data; 35 using System.Xml; 36 37 namespace MonoTests.System.Windows.Forms 38 { 39 // Helper classes 40 41 class TestDataGrid : DataGrid 42 { TestDataGrid()43 public TestDataGrid () 44 { 45 46 } 47 48 public CurrencyManager Manager { 49 get { 50 return ListManager; 51 } 52 } 53 } 54 55 [TestFixture] 56 public class DataGridTest : TestHelper 57 { 58 private bool eventhandled; 59 60 61 [Test] TestDefaultValues()62 public void TestDefaultValues () 63 { 64 DataGrid dg = new DataGrid (); 65 66 Assert.AreEqual (true, dg.AllowNavigation, "AllowNavigation property"); 67 Assert.AreEqual (true, dg.AllowSorting, "AllowSorting property"); 68 Assert.AreEqual (BorderStyle.Fixed3D, dg.BorderStyle, "BorderStyle property"); 69 Assert.AreEqual (string.Empty, dg.CaptionText, "CaptionText property"); 70 Assert.AreEqual (true, dg.CaptionVisible, "CaptionVisible property"); 71 Assert.AreEqual (true, dg.ColumnHeadersVisible, "ColumnHeadersVisible property"); 72 Assert.AreEqual (new DataGridCell (), dg.CurrentCell, "CurrentCell property"); 73 Assert.AreEqual (-1, dg.CurrentRowIndex, "CurrentRowIndex property"); 74 Assert.AreEqual (string.Empty, dg.DataMember, "DataMember property"); 75 Assert.AreEqual (null, dg.DataSource, "DataSource property"); 76 Assert.AreEqual (0, dg.FirstVisibleColumn, "FirstVisibleColumn property"); 77 Assert.AreEqual (false, dg.FlatMode, "FlatMode property"); 78 Assert.AreEqual (DataGridLineStyle.Solid, dg.GridLineStyle, "GridLineStyle property"); 79 Assert.AreEqual (DataGridParentRowsLabelStyle.Both, dg.ParentRowsLabelStyle, "ParentRowsLabelStyle property"); 80 Assert.AreEqual (true, dg.ParentRowsVisible, "ParentRowsVisible property"); 81 Assert.AreEqual (75, dg.PreferredColumnWidth, "PreferredColumnWidth property"); 82 //Assert.AreEqual (16, dg.PreferredRowHeight, "PreferredRowHeight property"); 83 Assert.AreEqual (false, dg.ReadOnly, "ReadOnly property"); 84 Assert.AreEqual (true, dg.RowHeadersVisible, "RowHeadersVisible property"); 85 Assert.AreEqual (35, dg.RowHeaderWidth, "RowHeaderWidth property"); 86 Assert.AreEqual (null, dg.Site, "Site property"); 87 Assert.AreEqual (string.Empty, dg.Text, "Text property"); 88 Assert.AreEqual (0, dg.VisibleColumnCount, "VisibleColumnCount property"); 89 90 // Font 91 Assert.IsFalse (dg.Font.Bold, "Font Bold"); 92 Assert.IsTrue (dg.Font.IsSystemFont, "Font IsSystemFont"); 93 Assert.IsFalse (dg.Font.Italic, "Font Italic"); 94 Assert.IsFalse (dg.Font.Strikeout, "Font Strikeout"); 95 Assert.IsFalse (dg.Font.Underline, "Font Underline"); 96 } 97 98 [Test] TestAllowNavigationChangedEvent()99 public void TestAllowNavigationChangedEvent () 100 { 101 DataGrid dg = new DataGrid (); 102 eventhandled = false; 103 dg.AllowNavigationChanged += new EventHandler (OnEventHandler); 104 dg.AllowNavigation = !dg.AllowNavigation; 105 Assert.AreEqual (true, eventhandled, "A1"); 106 } 107 108 [Test] TestBackgroundColorChangedEvent()109 public void TestBackgroundColorChangedEvent () 110 { 111 DataGrid dg = new DataGrid (); 112 eventhandled = false; 113 dg.BackgroundColorChanged += new EventHandler (OnEventHandler); 114 dg.BackgroundColor = Color.Red; 115 Assert.AreEqual (true, eventhandled, "A1"); 116 } 117 118 [Test] TestBorderStyleChangedEvent()119 public void TestBorderStyleChangedEvent () 120 { 121 DataGrid dg = new DataGrid (); 122 eventhandled = false; 123 dg.BorderStyleChanged += new EventHandler (OnEventHandler); 124 dg.BorderStyle = BorderStyle.None; 125 Assert.AreEqual (true, eventhandled, "A1"); 126 } 127 128 [Test] TestCaptionVisibleChangedEvent()129 public void TestCaptionVisibleChangedEvent () 130 { 131 DataGrid dg = new DataGrid (); 132 eventhandled = false; 133 dg.CaptionVisibleChanged += new EventHandler (OnEventHandler); 134 dg.CaptionVisible = !dg.CaptionVisible; 135 Assert.AreEqual (true, eventhandled, "A1"); 136 } 137 138 [Test] TestFlatModeChangedEvent()139 public void TestFlatModeChangedEvent () 140 { 141 DataGrid dg = new DataGrid (); 142 eventhandled = false; 143 dg.FlatModeChanged += new EventHandler (OnEventHandler); 144 dg.FlatMode = !dg.FlatMode; 145 Assert.AreEqual (true, eventhandled, "A1"); 146 } 147 148 [Test] CaptionFont()149 public void CaptionFont () 150 { 151 DataGrid dg = new DataGrid (); 152 153 // default values 154 Assert.IsTrue (dg.CaptionFont.Bold, "#A1"); 155 Assert.AreEqual (dg.CaptionFont.FontFamily, dg.Font.FontFamily, "#A2"); 156 Assert.AreEqual (dg.CaptionFont.Height, dg.Font.Height, "#A3"); 157 Assert.IsFalse(dg.CaptionFont.IsSystemFont, "#A4"); 158 Assert.AreEqual (dg.CaptionFont.Italic, dg.Font.Italic, "#A5"); 159 Assert.AreEqual (dg.CaptionFont.Name, dg.Font.Name, "#A6"); 160 Assert.AreEqual (dg.CaptionFont.Size, dg.Font.Size, "#A7"); 161 Assert.AreEqual (dg.CaptionFont.SizeInPoints, dg.Font.SizeInPoints, "#A8"); 162 Assert.AreEqual (dg.CaptionFont.Strikeout, dg.Font.Strikeout, "#A9"); 163 Assert.AreEqual (dg.CaptionFont.Underline, dg.Font.Underline, "#A10"); 164 Assert.AreEqual (dg.CaptionFont.Unit, dg.Font.Unit, "#A11"); 165 166 // modifying Font affects CaptionFont, except for FontStyle 167 dg.Font = new Font (dg.Font.FontFamily, 3, FontStyle.Italic); 168 Assert.IsTrue (dg.CaptionFont.Bold, "#B1"); 169 Assert.IsFalse (dg.Font.Bold, "#B2"); 170 Assert.IsFalse (dg.CaptionFont.Italic, "#B3"); 171 Assert.IsTrue (dg.Font.Italic, "#B4"); 172 Assert.AreEqual (3, dg.Font.SizeInPoints, "#B5"); 173 Assert.AreEqual (dg.CaptionFont.SizeInPoints, dg.Font.SizeInPoints, "#B6"); 174 175 // explicitly setting CaptionFont removes link between CaptionFont 176 // and Font 177 dg.CaptionFont = dg.Font; 178 Assert.AreSame (dg.CaptionFont, dg.Font, "#C1"); 179 dg.Font = new Font (dg.Font.FontFamily, 7, FontStyle.Bold); 180 Assert.IsFalse (dg.CaptionFont.Bold, "#C2"); 181 Assert.IsTrue (dg.Font.Bold, "#C3"); 182 Assert.AreEqual (7, dg.Font.SizeInPoints, "#C4"); 183 Assert.AreEqual (3, dg.CaptionFont.SizeInPoints, "#C5"); 184 } 185 186 [Test] HeaderFont()187 public void HeaderFont () 188 { 189 DataGrid dg = new DataGrid (); 190 dg.Font = new Font (dg.Font, FontStyle.Italic); 191 Assert.AreSame (dg.HeaderFont, dg.Font, "#1"); 192 193 dg.HeaderFont = dg.Font; 194 Assert.AreSame (dg.HeaderFont, dg.Font, "#2"); 195 196 dg.Font = new Font (dg.Font, FontStyle.Regular); 197 Assert.IsTrue (dg.HeaderFont.Italic, "#3"); 198 Assert.IsFalse (dg.Font.Italic, "#4"); 199 200 dg.ResetHeaderFont (); 201 Assert.AreSame (dg.HeaderFont, dg.Font, "#5"); 202 } 203 204 205 [Test] TestParentRowsLabelStyleChangedEvent()206 public void TestParentRowsLabelStyleChangedEvent () 207 { 208 DataGrid dg = new DataGrid (); 209 eventhandled = false; 210 dg.ParentRowsLabelStyleChanged += new EventHandler (OnEventHandler); 211 dg.ParentRowsLabelStyle = DataGridParentRowsLabelStyle.None; 212 Assert.AreEqual (true, eventhandled, "A1"); 213 } 214 215 [Test] TestParentRowsVisibleChangedEvent()216 public void TestParentRowsVisibleChangedEvent () 217 { 218 DataGrid dg = new DataGrid (); 219 eventhandled = false; 220 dg.ParentRowsVisibleChanged += new EventHandler (OnEventHandler); 221 dg.ParentRowsVisible = !dg.ParentRowsVisible; 222 Assert.AreEqual (true, eventhandled, "A1"); 223 } 224 225 [Test] TestReadOnlyChangedEvent()226 public void TestReadOnlyChangedEvent () 227 { 228 DataGrid dg = new DataGrid (); 229 eventhandled = false; 230 dg.ReadOnlyChanged += new EventHandler (OnEventHandler); 231 dg.ReadOnly = !dg.ReadOnly; 232 Assert.AreEqual (true, eventhandled, "A1"); 233 } 234 OnEventHandler(object sender, EventArgs e)235 public void OnEventHandler (object sender, EventArgs e) 236 { 237 eventhandled = true; 238 } 239 240 // Property exceptions 241 242 [Test] 243 [ExpectedException (typeof (ArgumentException))] GridLineColorException()244 public void GridLineColorException () 245 { 246 DataGrid dg = new DataGrid (); 247 dg.GridLineColor = Color.Empty; 248 } 249 250 [Test] 251 [ExpectedException (typeof (ArgumentException))] HeaderBackColorException()252 public void HeaderBackColorException () 253 { 254 DataGrid dg = new DataGrid (); 255 dg.HeaderBackColor = Color.Empty; 256 } 257 258 [Test] 259 [ExpectedException (typeof (ArgumentException))] PreferredColumnWidthException()260 public void PreferredColumnWidthException () 261 { 262 DataGrid dg = new DataGrid (); 263 dg.PreferredColumnWidth = -1; 264 } 265 266 [Test] ResetAlternatingBackColor()267 public void ResetAlternatingBackColor () 268 { 269 DataGrid dg = new DataGrid (); 270 DataGrid dg2 = new DataGrid (); 271 dg2.AlternatingBackColor = Color.Red; 272 dg2.ResetAlternatingBackColor (); 273 Assert.AreEqual (dg.AlternatingBackColor, dg2.AlternatingBackColor, "A1"); 274 } 275 276 // Test reset colour methods 277 [Test] ResetBackColorMethod()278 public void ResetBackColorMethod () 279 { 280 DataGrid dg = new DataGrid (); 281 DataGrid dg2 = new DataGrid (); 282 dg2.BackColor = Color.Red; 283 dg2.ResetBackColor (); 284 Assert.AreEqual (dg.BackColor, dg2.BackColor, "A1"); 285 } 286 287 [Test] ResetForeColorMethod()288 public void ResetForeColorMethod () 289 { 290 DataGrid dg = new DataGrid (); 291 DataGrid dg2 = new DataGrid (); 292 dg2.ForeColor = Color.Red; 293 dg2.ResetForeColor (); 294 Assert.AreEqual (dg.ForeColor, dg2.ForeColor, "A1"); 295 } 296 297 [Test] ResetGridLineColorMethod()298 public void ResetGridLineColorMethod () 299 { 300 DataGrid dg = new DataGrid (); 301 DataGrid dg2 = new DataGrid (); 302 dg2.GridLineColor = Color.Red; 303 dg2.ResetGridLineColor (); 304 Assert.AreEqual (dg.GridLineColor, dg2.GridLineColor, "A1"); 305 } 306 307 [Test] ResetHeaderBackColorMethod()308 public void ResetHeaderBackColorMethod () 309 { 310 DataGrid dg = new DataGrid (); 311 DataGrid dg2 = new DataGrid (); 312 dg2.HeaderBackColor = Color.Red; 313 dg2.ResetHeaderBackColor (); 314 Assert.AreEqual (dg.HeaderBackColor, dg2.HeaderBackColor, "A1"); 315 } 316 317 [Test] ResetHeaderFontMethod()318 public void ResetHeaderFontMethod () 319 { 320 } 321 322 [Test] ResetHeaderForeColorMethod()323 public void ResetHeaderForeColorMethod () 324 { 325 DataGrid dg = new DataGrid (); 326 DataGrid dg2 = new DataGrid (); 327 dg2.HeaderForeColor = Color.Red; 328 dg2.ResetHeaderForeColor (); 329 Assert.AreEqual (dg.HeaderForeColor, dg2.HeaderForeColor, "A1"); 330 } 331 332 [Test] ResetLinkColorMethod()333 public void ResetLinkColorMethod () 334 { 335 DataGrid dg = new DataGrid (); 336 DataGrid dg2 = new DataGrid (); 337 dg2.LinkColor = Color.Red; 338 dg2.ResetLinkColor (); 339 Assert.AreEqual (dg.LinkColor, dg2.LinkColor, "A1"); 340 } 341 342 [Test] ResetLinkHoverColor()343 public void ResetLinkHoverColor () 344 { 345 DataGrid dg = new DataGrid (); 346 DataGrid dg2 = new DataGrid (); 347 dg2.LinkHoverColor = Color.Red; 348 dg2.ResetLinkHoverColor (); 349 Assert.AreEqual (dg.LinkHoverColor, dg2.LinkHoverColor, "A1"); 350 } 351 352 [Test] ResetSelectionBackColor()353 public void ResetSelectionBackColor () 354 { 355 DataGrid dg = new DataGrid (); 356 DataGrid dg2 = new DataGrid (); 357 dg2.SelectionBackColor = Color.Red; 358 dg2.ResetSelectionBackColor (); 359 Assert.AreEqual (dg.SelectionBackColor, dg2.SelectionBackColor, "A1"); 360 } 361 362 [Test] ResetSelectionForeColor()363 public void ResetSelectionForeColor () 364 { 365 DataGrid dg = new DataGrid (); 366 DataGrid dg2 = new DataGrid (); 367 dg2.SelectionForeColor = Color.Red; 368 dg2.ResetSelectionForeColor (); 369 Assert.AreEqual (dg.SelectionForeColor, dg2.SelectionForeColor, "A1"); 370 } 371 372 [Test] TestSetDataBinding()373 public void TestSetDataBinding () 374 { 375 DataGrid dg = new DataGrid (); 376 DataSet ds = new DataSet ("DataSet"); 377 DataTable dt = new DataTable ("DataTable"); 378 ds.Tables.Add (dt); 379 380 dg.SetDataBinding (ds, "DataTable"); 381 } 382 383 int data_source_changed_count = 0; OnDataSourceChanged(object sender, EventArgs e)384 void OnDataSourceChanged (object sender, EventArgs e) 385 { 386 data_source_changed_count ++; 387 } 388 389 [Test] TestManager1()390 public void TestManager1 () 391 { 392 TestDataGrid dg = new TestDataGrid (); 393 394 data_source_changed_count = 0; 395 dg.DataSourceChanged += new EventHandler (OnDataSourceChanged); 396 397 /* make sure everything is fine to start with */ 398 Assert.IsNull (dg.Manager, "A1"); 399 Assert.IsNull (dg.DataSource, "A2"); 400 Assert.AreEqual (dg.DataMember, "", "A3"); 401 // NotWorking Assert.AreEqual (0, data_source_changed_count, "A4"); 402 } 403 404 [Test] TestManagerSetDataMember()405 public void TestManagerSetDataMember () 406 { 407 TestDataGrid dg = new TestDataGrid (); 408 409 data_source_changed_count = 0; 410 dg.DataSourceChanged += new EventHandler (OnDataSourceChanged); 411 412 /* set the datamember to something */ 413 dg.DataMember = "hi there"; 414 Assert.IsNull (dg.Manager, "A1"); 415 // NotWorking Assert.AreEqual (0, data_source_changed_count, "A2"); 416 } 417 418 [Test] TestManagerSetDataSource()419 public void TestManagerSetDataSource () 420 { 421 TestDataGrid dg = new TestDataGrid (); 422 423 data_source_changed_count = 0; 424 dg.DataSourceChanged += new EventHandler (OnDataSourceChanged); 425 426 /* set our datasource to something */ 427 dg = new TestDataGrid (); 428 DataSet ds = new DataSet ("DataSet"); 429 DataTable dt = new DataTable ("DataTable"); 430 ds.Tables.Add (dt); 431 432 dg.DataSource = ds; 433 Assert.IsNull (dg.Manager, "A1"); 434 435 /* set the datamember to something as well.. anything yet? */ 436 dg.DataMember = "DataTable"; 437 Assert.IsNull (dg.Manager, "A2"); 438 Assert.AreEqual (0, data_source_changed_count, "A3"); 439 } 440 441 [Test] TestManagerCreateHandle()442 public void TestManagerCreateHandle () 443 { 444 TestDataGrid dg = new TestDataGrid (); 445 446 data_source_changed_count = 0; 447 dg.DataSourceChanged += new EventHandler (OnDataSourceChanged); 448 449 /* set our datasource to something */ 450 dg = new TestDataGrid (); 451 DataSet ds = new DataSet ("DataSet"); 452 DataTable dt = new DataTable ("DataTable"); 453 ds.Tables.Add (dt); 454 455 dg.DataSource = ds; 456 457 /* cause the control to create its handle and 458 * see if that does anything */ 459 Assert.IsNotNull (dg.Handle, "A1"); 460 Assert.IsNull (dg.Manager, "A2"); 461 Assert.AreEqual (0, data_source_changed_count, "A3"); 462 } 463 464 [Test] TestManagerSetBindingContext()465 public void TestManagerSetBindingContext () 466 { 467 TestDataGrid dg = new TestDataGrid (); 468 469 data_source_changed_count = 0; 470 dg.DataSourceChanged += new EventHandler (OnDataSourceChanged); 471 472 /* set our datasource to something */ 473 dg = new TestDataGrid (); 474 DataSet ds = new DataSet ("DataSet"); 475 DataTable dt = new DataTable ("DataTable"); 476 ds.Tables.Add (dt); 477 478 dg.DataSource = ds; 479 dg.DataMember = "DataTable"; 480 481 /* now set the BindingContext and see if something changes */ 482 dg.BindingContext = new BindingContext (); 483 Assert.IsNotNull (dg.Manager, "A1"); 484 Assert.AreEqual (0, data_source_changed_count, "A2"); 485 } 486 487 [Test] TestManagerAfterSetBindingContext()488 public void TestManagerAfterSetBindingContext () 489 { 490 TestDataGrid dg = new TestDataGrid (); 491 492 data_source_changed_count = 0; 493 dg.DataSourceChanged += new EventHandler (OnDataSourceChanged); 494 495 dg.BindingContext = new BindingContext (); 496 497 /* set our datasource to something */ 498 dg = new TestDataGrid (); 499 DataSet ds = new DataSet ("DataSet"); 500 DataTable dt = new DataTable ("DataTable"); 501 ds.Tables.Add (dt); 502 503 dg.DataSource = ds; 504 Assert.IsNull (dg.Manager, "A1"); 505 506 dg.DataMember = "DataTable"; 507 Assert.IsNull (dg.Manager, "A2"); 508 509 dg.BindingContext = new BindingContext (); 510 Assert.IsNotNull (dg.Manager, "A3"); 511 // NotWorking Assert.AreEqual (0, data_source_changed_count, "A4"); 512 } 513 514 [Test] TestManagerSetDataMemberAfterSetBindingContext()515 public void TestManagerSetDataMemberAfterSetBindingContext () 516 { 517 TestDataGrid dg = new TestDataGrid (); 518 519 data_source_changed_count = 0; 520 dg.DataSourceChanged += new EventHandler (OnDataSourceChanged); 521 522 /* set our datasource to something */ 523 dg = new TestDataGrid (); 524 DataSet ds = new DataSet ("DataSet"); 525 DataTable dt = new DataTable ("DataTable"); 526 ds.Tables.Add (dt); 527 528 dg.DataSource = ds; 529 530 dg.BindingContext = new BindingContext (); 531 Assert.AreEqual (0, data_source_changed_count, "A1"); 532 533 CurrencyManager mgr = dg.Manager; 534 535 dg.DataMember = "DataTable"; 536 Assert.IsNotNull (dg.Manager, "A2"); 537 Assert.IsTrue (mgr != dg.Manager, "A3"); 538 Assert.AreEqual (0, data_source_changed_count, "A4"); 539 } 540 541 [Test] TestManagerSetDataSourceAfterSetBindingContext()542 public void TestManagerSetDataSourceAfterSetBindingContext () 543 { 544 TestDataGrid dg = new TestDataGrid (); 545 546 data_source_changed_count = 0; 547 dg.DataSourceChanged += new EventHandler (OnDataSourceChanged); 548 549 /* set our datasource to something */ 550 dg = new TestDataGrid (); 551 DataSet ds = new DataSet ("DataSet"); 552 DataTable dt = new DataTable ("DataTable"); 553 ds.Tables.Add (dt); 554 555 dg.DataMember = "DataTable"; 556 557 dg.BindingContext = new BindingContext (); 558 Assert.AreEqual (0, data_source_changed_count, "A1"); 559 560 CurrencyManager mgr = dg.Manager; 561 562 dg.DataSource = ds; 563 Assert.IsNotNull (dg.Manager, "A2"); 564 Assert.IsTrue (mgr != dg.Manager, "A3"); 565 Assert.AreEqual (0, data_source_changed_count, "A4"); 566 } 567 568 [Test] TestManagerSetDataSourceAfterSetBindingContextWithHandle()569 public void TestManagerSetDataSourceAfterSetBindingContextWithHandle () 570 { 571 TestDataGrid dg = new TestDataGrid (); 572 573 data_source_changed_count = 0; 574 dg.DataSourceChanged += new EventHandler (OnDataSourceChanged); 575 576 /* set our datasource to something */ 577 dg = new TestDataGrid (); 578 DataSet ds = new DataSet ("DataSet"); 579 DataTable dt = new DataTable ("DataTable"); 580 ds.Tables.Add (dt); 581 582 /* cause the control to create its handle and 583 * see if that does anything */ 584 Assert.IsNotNull (dg.Handle, "A1"); 585 586 dg.DataSource = new ArrayList (); 587 588 dg.BindingContext = new BindingContext (); 589 Assert.AreEqual (0, data_source_changed_count, "A2"); 590 591 dg.DataSource = ds; 592 Assert.AreEqual (0, data_source_changed_count, "A3"); 593 } 594 595 [Test] TestManagerSetDataSourceWithEmptyStyle()596 public void TestManagerSetDataSourceWithEmptyStyle () 597 { 598 TestDataGrid dg = new TestDataGrid (); 599 dg.BindingContext = new BindingContext (); 600 601 DataSet ds = new DataSet ("DataSet"); 602 DataTable dt = new DataTable ("MyTable"); 603 dt.Columns.Add ("A", typeof (string)); 604 dt.NewRow (); 605 ds.Tables.Add (dt); 606 607 // Add the style for the table we have, but leave it empty 608 // - this is, no column styles 609 DataGridTableStyle table_style = new DataGridTableStyle (); 610 table_style.MappingName = "MyTable"; 611 dg.TableStyles.Add (table_style); 612 613 Assert.AreEqual (0, table_style.GridColumnStyles.Count, "#A1"); 614 615 dg.DataSource = dt; 616 617 Assert.AreEqual (1, table_style.GridColumnStyles.Count, "#B1"); 618 } 619 620 public class ClickableDataGrid : DataGrid 621 { ClickGrid(int X, int Y)622 public void ClickGrid (int X, int Y) 623 { 624 MouseEventArgs me = new MouseEventArgs ( 625 MouseButtons.Left, 626 1, /*# of clicks*/ 627 X, Y, 0); 628 OnMouseDown (me); 629 OnClick (me); 630 OnMouseUp (me); 631 } 632 } 633 634 public class Form5487 : Form 635 { 636 private ClickableDataGrid dataGrid1; 637 private Container components = null; 638 Form5487()639 public Form5487 () 640 { 641 InitializeComponent (); 642 } 643 Dispose(bool disposing)644 protected override void Dispose (bool disposing) 645 { 646 if (disposing) { 647 if (components != null) { 648 components.Dispose (); 649 } 650 } 651 base.Dispose (disposing); 652 } 653 InitializeComponent()654 private void InitializeComponent () 655 { 656 this.dataGrid1 = new ClickableDataGrid (); 657 ((ISupportInitialize)(this.dataGrid1)).BeginInit (); 658 this.SuspendLayout (); 659 this.dataGrid1.DataMember = ""; 660 this.dataGrid1.HeaderForeColor = SystemColors.ControlText; 661 this.dataGrid1.Location = new Point (16, 16); 662 this.dataGrid1.Name = "dataGrid1"; 663 this.dataGrid1.Size = new Size (624, 440); 664 this.dataGrid1.TabIndex = 0; 665 this.AutoScaleBaseSize = new Size (5, 13); 666 this.ClientSize = new Size (656, 470); 667 this.Controls.Add (this.dataGrid1); 668 this.Name = "Form1"; 669 this.Text = "Form1"; 670 this.Shown += new EventHandler (this.Form1_Load); 671 ((ISupportInitialize)(this.dataGrid1)).EndInit (); 672 this.ResumeLayout (false); 673 674 } 675 Form1_Load(object sender, EventArgs e)676 private void Form1_Load (object sender, EventArgs e) 677 { 678 DataSet ds = new DataSet (); 679 String XMLString = ""; 680 XmlTextReader XMLTR; 681 682 XMLString += "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"; 683 XMLString += "<pa><pb><pc><pd><id>1</id>"; 684 XMLString += "</pd></pc><pc><pd><id>1</id>"; 685 XMLString += "</pd><pd><id>1</id></pd><pd>"; 686 XMLString += "<id>1</id></pd><pd><id>1</id>"; 687 XMLString += "</pd><pd><id>1</id></pd><pd>"; 688 XMLString += "<id>1</id></pd><pd><id>1</id>"; 689 XMLString += "</pd><pd><id>1</id></pd></pc>"; 690 XMLString += "</pb></pa>"; 691 XMLTR = new XmlTextReader (XMLString, 692 XmlNodeType.Document, null); 693 XMLTR.ReadOuterXml (); 694 ds.ReadXml (XMLTR); 695 this.dataGrid1.DataSource = ds; 696 this.dataGrid1.ClickGrid (25, 45); 697 Application.DoEvents (); 698 this.dataGrid1.ClickGrid (46, 73); 699 Application.DoEvents (); 700 this.dataGrid1.NavigateBack (); 701 Close (); 702 } 703 } 704 [Test] Bug5487AndRelated()705 public void Bug5487AndRelated () 706 { 707 //this should crash on fail 708 Application.Run (new Form5487 ()); 709 } 710 } 711 } 712