[Mono-bugs] [Bug 78301][Nor] New - Datagrid TableStyle work incorrectly

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Fri May 5 04:32:11 EDT 2006


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by wilow at orange.pl.

http://bugzilla.ximian.com/show_bug.cgi?id=78301

--- shadow/78301	2006-05-05 04:32:11.000000000 -0400
+++ shadow/78301.tmp.11402	2006-05-05 04:32:11.000000000 -0400
@@ -0,0 +1,162 @@
+Bug#: 78301
+Product: Mono: Class Libraries
+Version: 1.1
+OS: All
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: Windows.Forms
+AssignedTo: jordimash at gmail.com                            
+ReportedBy: wilow at orange.pl               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Datagrid TableStyle work incorrectly 
+
+Description of Problem:
+I'm using DataGrid with DataTable dynamically created. At first you call
+PrepareDataTable method, and then SetDataGridStyle.
+In TableStyle there are defined only 3 columns, so 2 of them should be not
+visible, but I've noticed that mono add automatically rest of columns. So
+after invocation of this code, I have datagrid with: Column 1, Column 2,
+Column 3, Column 4, Column 5, but I wanted Column 1, Column 2, Column 3.
+
+Steps to reproduce the problem, use this code:
+// -- CODE --
+using System;
+using System.Drawing;
+using System.Windows.Forms;
+using System.Data;
+
+namespace datagrid_test
+{
+	public class MainForm : System.Windows.Forms.Form
+	{
+		private System.Windows.Forms.Button button1;
+		private System.Windows.Forms.DataGrid dataGrid1;
+		
+		private DataTable m_someDataTable;
+		
+		public MainForm()
+		{
+			InitializeComponent();
+			
+			PrepareDataTable();
+			SetDataGridStyle();
+		}
+		
+		[STAThread]
+		public static void Main(string[] args)
+		{
+			Application.Run(new MainForm());
+		}
+		
+		#region Windows Forms Designer generated code		
+		private void InitializeComponent()
+		{
+			this.dataGrid1 = new System.Windows.Forms.DataGrid();
+			this.button1 = new System.Windows.Forms.Button();
+			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
+			this.SuspendLayout();
+			// 
+			// dataGrid1
+			// 
+			this.dataGrid1.DataMember = "";
+			this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
+			this.dataGrid1.Location = new System.Drawing.Point(8, 4);
+			this.dataGrid1.Name = "dataGrid1";
+			this.dataGrid1.Size = new System.Drawing.Size(524, 152);
+			this.dataGrid1.TabIndex = 0;
+			// 
+			// button1
+			// 
+			this.button1.Location = new System.Drawing.Point(12, 168);
+			this.button1.Name = "button1";
+			this.button1.TabIndex = 1;
+			this.button1.Text = "button1";
+			this.button1.Click += new System.EventHandler(this.Button1Click);
+			// 
+			// MainForm
+			// 
+			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
+			this.ClientSize = new System.Drawing.Size(540, 203);
+			this.Controls.Add(this.button1);
+			this.Controls.Add(this.dataGrid1);
+			this.Name = "MainForm";
+			this.Text = "MainForm";
+			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
+			this.ResumeLayout(false);
+		}
+		#endregion
+				
+		private void PrepareDataTable()
+		{
+			m_someDataTable = new DataTable("Queue");
+			DataColumn dc;
+			
+			dc = new DataColumn("Col1", typeof(int));
+			m_someDataTable.Columns.Add(dc);
+			dc = new DataColumn("Col2", typeof(string));
+			m_someDataTable.Columns.Add(dc);
+			dc = new DataColumn("Col3", typeof(string));
+			m_someDataTable.Columns.Add(dc);
+			dc = new DataColumn("Col4", typeof(string));
+			m_someDataTable.Columns.Add(dc);
+			dc = new DataColumn("Col5", typeof(int));
+			m_someDataTable.Columns.Add(dc);			
+		}
+		
+		private void SetDataGridStyle()
+		{
+			DataGridTableStyle table = new DataGridTableStyle();
+			table.ReadOnly = true;
+			table.RowHeadersVisible = false;
+			table.MappingName = "Queue";
+			
+			DataGridColumnStyle style;
+			
+			style = new DataGridTextBoxColumn();
+			style.MappingName = "Col1";
+			style.HeaderText = "Column 1";
+			table.GridColumnStyles.Add(style);
+			
+			style = new DataGridTextBoxColumn();
+			style.MappingName = "Col2";
+			style.HeaderText = "Column 2";
+			table.GridColumnStyles.Add(style);
+			
+			style = new DataGridTextBoxColumn();
+			style.MappingName = "Col3";
+			style.HeaderText = "Column 3";
+			table.GridColumnStyles.Add(style);
+			
+			dataGrid1.TableStyles.Add(table);
+			
+			dataGrid1.DataSource = m_someDataTable;
+		}
+		
+		void Button1Click(object sender, System.EventArgs e)
+		{
+			DataRow row = m_someDataTable.NewRow();
+			row[0] = 5;
+			row[1] = "a";
+			row[2] = "b";
+			row[3] = "c";
+			row[4] = 6;
+			m_someDataTable.Rows.Add(row);
+		}		
+	}
+}
+// -- CODE --
+
+Actual Results:
+Datagrid with Column 1, Column 2, Column 3, Column 4, Column 5.
+
+Expected Results:
+Datagrid with Column 1, Column 2, Column 3.
+
+How often does this happen? 
+Always


More information about the mono-bugs mailing list