[Mono-winforms-list] DataGrid InvalidArgument problem when row is changed

URBAN Leos leos.urban at qds.cz
Sun Jan 21 03:17:32 EST 2007


Hello,
I am novice to mono and dotnet, I tested some examples with Mono on my 
Linux FC3 and have problem with DataGrid.

When I select row in datagrid and then click to another row I got 
Exception and application crashes. Sometime on first click, sometime 
more clicks. But crashes everytime.

The same application (compiled on Linux with Mono), when is runned under 
Windows (and MS dotnet), works fine.

If you have some tip, please help.

I looked for some list archive but not find.
Hope that I do not send the question what was here yesterday...


Thanks
Leos

Exception is:
System.ArgumentException: '17' is not a valid value for 'Value'. 'Value' 
should be between 'Minimum' and 'Maximum'
   at System.Windows.Forms.ScrollBar.set_Value (Int32 value) [0x00000]
   at (wrapper remoting-invoke-with-check) 
System.Windows.Forms.ScrollBar:set_Value (int)
   at System.Windows.Forms.TextBoxBase.CaretMoved (System.Object sender, 
System.EventArgs e) [0x00000]
   at System.Windows.Forms.TextBoxBase.ScrollToCaret () [0x00000]
   at System.Windows.Forms.TextBoxBase.set_Text (System.String value) 
[0x00000]
   at System.Windows.Forms.TextBox.set_Text (System.String value) [0x00000]
   at System.Windows.Forms.DataGridTextBoxColumn.Edit 
(System.Windows.Forms.CurrencyManager source, Int32 rowNum, Rectangle 
bounds, Boolean _ro, System.String instantText, Boolean cellIsVisible) 
[0x00000]
   at System.Windows.Forms.DataGrid.Edit () [0x00000]
   at System.Windows.Forms.DataGrid.ScrollToColumnInPixels (Int32 pixel) 
[0x00000]
   at System.Windows.Forms.DataGrid.EnsureCellVisibility (DataGridCell 
cell) [0x00000]
   at System.Windows.Forms.DataGrid.set_CurrentCell (DataGridCell value) 
[0x00000]
   at System.Windows.Forms.DataGrid.set_CurrentRow (Int32 value) [0x00000]
   at System.Windows.Forms.DataGrid.OnMouseDown 
(System.Windows.Forms.MouseEventArgs e) [0x00000]
   at System.Windows.Forms.Control.WndProc 
(System.Windows.Forms.Message& m) [0x00000]
   at System.Windows.Forms.Control+ControlNativeWindow.WndProc 
(System.Windows.Forms.Message& m) [0x00000]
   at System.Windows.Forms.NativeWindow.WndProc (IntPtr hWnd, Msg msg, 
IntPtr wParam, IntPtr lParam) [0x00000]


Mono Version (downloaded by yum from Mono repository 3 days ago):
mono-basic-1.2.2-0.novell
mono-data-oracle-1.2.2.1-0.novell
mono-core-1.2.2.1-0.novell
mono-data-postgresql-1.2.2.1-0.novell
mono-web-1.2.2.1-0.novell
mono-nunit-1.2.2.1-0.novell
mono-winforms-1.2.2.1-0.novell
mono-data-sybase-1.2.2.1-0.novell
monodevelop-0.12-0.novell
mono-data-1.2.2.1-0.novell
mono-devel-1.2.2.1-0.novell
monodoc-core-1.2.1-1.novell
mono-data-sqlite-1.2.2.1-0.novell

My code is (based on MSDN example):
// mcs /t:winexe -reference:System.Windows.Forms,System.Drawing Form8.cs
// mono Form8.exe
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Data;
public class Form8 :Form
{
   //Declare
   private Button btn;
   private DataSet ds;
   private DataGrid dg;

   public static void Main()
   {
     Application.Run(new Form8());
   }

   //Constructor
   public Form8()
   {
     btn = new System.Windows.Forms.Button();
     btn.Location = new System.Drawing.Point (10, 10);
     btn.Size = new System.Drawing.Size (580, 30);
     btn.Text = "Create DataSet";
     btn.Click += new System.EventHandler (this.btn_Click);

     dg = new System.Windows.Forms.DataGrid();
     dg.Location = new System.Drawing.Point (10, 50);
     dg.Size = new System.Drawing.Size (580, 400);

     this.StartPosition = 
System.Windows.Forms.FormStartPosition.CenterParent;
     this.ClientSize = new System.Drawing.Size (600, 450);

     //Add the object to the Form
     this.Controls.Add(btn);
     this.Controls.Add(dg);
   }

   public void btn_Click(object sender, System.EventArgs e)
   {
       MakeParentTable();
       MakeChildTable();
       MakeDataRelation();
       BindToDataGrid();
   }

   private void MakeParentTable()
   {
     DataTable table = new DataTable("ParentTable");
     DataColumn column;
     DataRow row;

     column = new DataColumn();
     column.ColumnName = "id";
     column.DataType = System.Type.GetType("System.Int32");
     column.ReadOnly = true;
     column.Unique = true;
     table.Columns.Add(column);

     column = new DataColumn();
     column.ColumnName = "ParentItem";
     column.DataType = System.Type.GetType("System.String");
     column.AutoIncrement = false;
     column.Caption = "ParentItem";
     column.ReadOnly = false;
     column.Unique = false;
     table.Columns.Add(column);

     DataColumn[] PrimaryKeyColumns = new DataColumn[1];
     PrimaryKeyColumns[0] = table.Columns["id"];
     table.PrimaryKey = PrimaryKeyColumns;

     ds = new DataSet();
     ds.Tables.Add(table);

     for (int i = 0; i<= 2; i++)
     {
         row = table.NewRow();
         row["id"] = i;
         row["ParentItem"] = "ParentItem " + i;
         table.Rows.Add(row);
     }
   }

   private void MakeChildTable()
   {
     DataTable table = new DataTable("ChildTable");
     DataColumn column;
     DataRow row;

     column = new DataColumn();
     column.ColumnName = "ChildID";
     column.DataType= System.Type.GetType("System.Int32");
     column.AutoIncrement = true;
     column.Caption = "ID";
     column.ReadOnly = true;
     column.Unique = true;
     table.Columns.Add(column);

     column = new DataColumn();
     column.ColumnName = "ChildItem";
     column.DataType= System.Type.GetType("System.String");
     column.AutoIncrement = false;
     column.Caption = "ChildItem";
     column.ReadOnly = false;
     column.Unique = false;
     table.Columns.Add(column);

     column = new DataColumn();
     column.ColumnName = "ParentID";
     column.DataType= System.Type.GetType("System.Int32");
     column.AutoIncrement = false;
     column.Caption = "ParentID";
     column.ReadOnly = false;
     column.Unique = false;
     table.Columns.Add(column);

     ds.Tables.Add(table);

     for(int i = 0; i <= 4; i ++)
     {
         row = table.NewRow();
         row["ChildID"] = i;
         row["ChildItem"] = "Item " + i;
         row["ParentID"] = 0 ;
         table.Rows.Add(row);
     }
     for(int i = 0; i <= 4; i ++)
     {
         row = table.NewRow();
         row["ChildID"] = i + 5;
         row["ChildItem"] = "Item " + i;
         row["ParentID"] = 1 ;
         table.Rows.Add(row);
     }
     for(int i = 0; i <= 4; i ++)
     {
         row = table.NewRow();
         row["ChildID"] = i + 10;
         row["ChildItem"] = "Item " + i;
         row["ParentID"] = 2 ;
         table.Rows.Add(row);
     }
   }

   private void MakeDataRelation()
   {
     DataColumn parentColumn = ds.Tables["ParentTable"].Columns["id"];
     DataColumn childColumn = ds.Tables["ChildTable"].Columns["ParentID"];
     DataRelation relation = new DataRelation("parent2Child", 
parentColumn, childColumn);
     ds.Tables["ChildTable"].ParentRelations.Add(relation);
   }

   private void BindToDataGrid()
   {
     dg.SetDataBinding(ds,"ParentTable");
   }

}


More information about the Mono-winforms-list mailing list