Re: datagrid datatable problem.

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: William Ryan eMVP (dotnetguru_at_comcast.nospam.net)
Date: 07/28/04


Date: Tue, 27 Jul 2004 22:49:56 -0400

can you tell me a little more about the problem.

Basicaly, you created a datatable and added some datacolumns. If you fill
the datatable, bind it to the grid and try to delete a row, everything is
fine. However if you sort the grid first and then delete a column - you get
an exception? If this is correct, can you tell me what exception you are
getting? does teh exception occur when you hit the delete button or does it
happen when you try to update the db (ie call .Update method of the
dataadapter?). Could you post teh code you are using for the delete?

-- 
W.G. Ryan MVP Windows - Embedded
Have an opinion on the effectiveness of Microsoft Embedded newsgroups?
Let Microsoft know!
https://www.windowsembeddedeval.com/community/newsgroups
"clyyy2002" <clyyy2002@yahoo.com.cn> wrote in message
news:uj5SCoEdEHA.596@TK2MSFTNGP11.phx.gbl...
> At added two column and more column hereafter,I immediately click del
> button,the program is no problem.
>
> but if i first click the DataGrid columnHeader and then click the del
> button, i find when column is
>
> finally ,a error is happen
>
> underside is my program.
>
>
>
>
>
>
>
> using System;
>
> using System.Drawing;
>
> using System.Collections;
>
> using System.ComponentModel;
>
> using System.Windows.Forms;
>
> using System.Data;
>
>
>
> namespace deldatagridcolumn
>
> {
>
>
>      public class Form1 : System.Windows.Forms.Form
>
>      {
>
>          private System.Windows.Forms.Button button1;
>
>          private System.Windows.Forms.Button button2;
>
>
>
>          private System.ComponentModel.Container components = null;
>
>          private System.Windows.Forms.DataGrid grid;
>
>
>
>          DataTable dt = new DataTable("T");
>
>
>
>          public Form1()
>
>          {
>
>
>               InitializeComponent();
>
>
>          }
>
>
>
>
>
>          protected override void Dispose( bool disposing )
>
>          {
>
>               if( disposing )
>
>               {
>
>                    if (components != null)
>
>                    {
>
>                        components.Dispose();
>
>                    }
>
>               }
>
>               base.Dispose( disposing );
>
>          }
>
>
>
>          #region Windows 窗体设计器生成的代码
>
>
>          private void InitializeComponent()
>
>          {
>
>               this.grid = new System.Windows.Forms.DataGrid();
>
>               this.button1 = new System.Windows.Forms.Button();
>
>               this.button2 = new System.Windows.Forms.Button();
>
>
> ((System.ComponentModel.ISupportInitialize)(this.grid)).BeginInit();
>
>               this.SuspendLayout();
>
>               //
>
>               // grid
>
>               //
>
>               this.grid.DataMember = "";
>
>               this.grid.HeaderForeColor =
> System.Drawing.SystemColors.ControlText;
>
>               this.grid.Location = new System.Drawing.Point(24, 16);
>
>               this.grid.Name = "grid";
>
>               this.grid.Size = new System.Drawing.Size(448, 288);
>
>               this.grid.TabIndex = 0;
>
>               //
>
>               // button1
>
>               //
>
>               this.button1.Location = new System.Drawing.Point(304, 312);
>
>               this.button1.Name = "button1";
>
>               this.button1.TabIndex = 1;
>
>               this.button1.Text = "Add";
>
>               this.button1.Click += new
> System.EventHandler(this.button1_Click);
>
>               //
>
>               // button2
>
>               //
>
>               this.button2.Location = new System.Drawing.Point(400, 312);
>
>               this.button2.Name = "button2";
>
>               this.button2.TabIndex = 2;
>
>               this.button2.Text = "Del";
>
>               this.button2.Click += new
> System.EventHandler(this.button2_Click);
>
>               //
>
>               // Form1
>
>               //
>
>               this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
>
>               this.ClientSize = new System.Drawing.Size(504, 341);
>
>               this.Controls.Add(this.button2);
>
>               this.Controls.Add(this.button1);
>
>               this.Controls.Add(this.grid);
>
>               this.Name = "Form1";
>
>               this.Text = "Form1";
>
>               this.Load += new System.EventHandler(this.Form1_Load);
>
>
> ((System.ComponentModel.ISupportInitialize)(this.grid)).EndInit();
>
>               this.ResumeLayout(false);
>
>
>
>          }
>
>          #endregion
>
>
>
>
>          [STAThread]
>
>          static void Main()
>
>          {
>
>               Application.Run(new Form1());
>
>          }
>
>
>
>          private void Form1_Load(object sender, System.EventArgs e)
>
>          {
>
>               DataColumn dc = new DataColumn("dcode",typeof(string));
>
>               dt.Columns.Add(dc);
>
>               DataRow dr = dt.NewRow();
>
>               dr[0] = "aa";
>
>               dt.Rows.Add(dr);
>
>
>
>               grid.DataSource = dt;
>
>               DataGridTableStyle myGridStyle = new DataGridTableStyle();
>
>               myGridStyle.MappingName = "T";
>
>
>
>               DataGridTextBoxColumn style = new DataGridTextBoxColumn();
>
>
>
>               style.MappingName  = "dcode";
>
>               style.HeaderText   = "DCODE";
>
>               style.Width            = 100;
>
>
>
>               myGridStyle.GridColumnStyles.Add(style);
>
>               grid.TableStyles.Add(myGridStyle);
>
>          }
>
>
>
>          private void button1_Click(object sender, System.EventArgs e)
>
>          {
>
>
>               string FieldEn = "";
>
>               int i=0;
>
>               int j=0;
>
>               string caption = "";
>
>               while(FieldEn.Length==0)
>
>               {
>
>
>
>
>                    for(j=0;j<dt.Columns.Count;j++)
>
>                    {
>
>                        if(("F" + i.ToString()) ==
dt.Columns[j].ColumnName)
>
>                        {
>
>                             break;
>
>                        }
>
>                    }
>
>
>
>
>                    if(j==dt.Columns.Count)
>
>                    {
>
>                        FieldEn = "F" + i.ToString();
>
>                        caption = "f" + i.ToString();
>
>                        break;
>
>                    }
>
>                    i++;
>
>               }
>
>
>
>
>
>               DataColumn column = new DataColumn(FieldEn,typeof(string));
>
>               column.Caption = caption;
>
>
>
>               dt.Columns.Add(column);
>
>               DataGridTextBoxColumn myGridStyle = new
> DataGridTextBoxColumn();
>
>               myGridStyle.MappingName = column.ColumnName;
>
>               myGridStyle.HeaderText = column.Caption;
>
>               myGridStyle.Width      = 100;
>
>               grid.TableStyles[0].GridColumnStyles.Add(myGridStyle);
>
>          }
>
>
>
>          private void button2_Click(object sender, System.EventArgs e)
>
>          {
>
>               if(dt.Columns.Count > 1)
>
>               {
>
>                    dt.Columns.RemoveAt(1);
>
>                    grid.TableStyles[0].GridColumnStyles.RemoveAt(1);
>
>               }
>
>          }
>
>      }
>
> }
>
>
>
>
>
>
>


Relevant Pages

  • Re: Exception error when accessing the class variable at the termination of the program
    ... If the last statement del x2, is removed, then when the program terminates, this throws up an exception as shown below ... exceptions that occur during their execution are ... explicit finalizer method in this case, ...
    (comp.lang.python)
  • Re: System.Data ExecuteReader requires an open and available Connection
    ... "William Vaughn" wrote in message ... should NOT be getting an exception if there aren't any rows? ... > William (Bill) Vaughn ... >> Have an opinion on the effectiveness of Microsoft Embedded newsgroups? ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Dataset.Clear() takes a looonnnggg time
    ... would become eligible for garbage collection (which would happen at some ... > I have tried simply assigning the reference a new instance of the dataset ... >> exception being raised or anything? ... >> Have an opinion on the effectiveness of Microsoft Embedded newsgroups? ...
    (microsoft.public.dotnet.framework.adonet)
  • Exception error when accessing the class variable at the termination of the program
    ... If the last statement del x2, is removed, then when the program terminates, this throws up an exception as shown below ... Krishna is now created ... Can someone please explain why the exception happens in the case where there is no explicit del statement? ...
    (comp.lang.python)
  • Re: Help on SQLCE
    ... What is the exception that you get? ... Have an opinion on the effectiveness of Microsoft Embedded newsgroups? ...
    (microsoft.public.dotnet.framework.compactframework)