Adding a new row also adds an extra row

4 posts, 0 answers
  1. Tony
    Tony avatar
    2 posts
    Member since:
    Dec 2010

    Posted 22 May 2012 Link to this post

    I have a gridview bound to an BindingList<> and it allows the user to add a new row.  Whenever the user clicks on the add new row area, the grid immediately inserts 2 new rows  one of them overlaps the area with the prompt "Click here to add a new row".  Once the user is done editing one of the rows.  An IndexOutOfRangeException is thrown when the grid tries to set the value to the extra row.  How can I avoid this?

    public NoteHistoryControl()
            {
                InitializeComponent();
                this.noteHistoryGridView.DataSource = new BindingList<Note>(this._noteHistory);
            }
     
     
            private void noteHistoryGridView_CellValueChanged(object sender, Telerik.WinControls.UI.GridViewCellEventArgs e)
            {
                GridViewDataColumn column = e.Column as GridViewDataColumn;
                if (column != null && column.FieldName == "Text")
                {
                    this._noteText = e.Value.ToString();
                    this.noteHistoryGridView.MasterGridViewTemplate.AllowAddNewRow = false;
                }
            }

    private void InitializeComponent()
            {
                Telerik.WinControls.UI.GridViewTextBoxColumn gridViewTextBoxColumn1 = new Telerik.WinControls.UI.GridViewTextBoxColumn();
                Telerik.WinControls.UI.GridViewDateTimeColumn gridViewDateTimeColumn1 = new Telerik.WinControls.UI.GridViewDateTimeColumn();
                Telerik.WinControls.UI.GridViewTextBoxColumn gridViewTextBoxColumn2 = new Telerik.WinControls.UI.GridViewTextBoxColumn();
                Telerik.WinControls.UI.GridSortField gridSortField1 = new Telerik.WinControls.UI.GridSortField();
                this.panel1 = new System.Windows.Forms.Panel();
                this.noteLabel = new System.Windows.Forms.Label();
                this.noteHistoryGridView = new Telerik.WinControls.UI.RadGridView();
                this.panel1.SuspendLayout();
                ((System.ComponentModel.ISupportInitialize)(this.noteHistoryGridView)).BeginInit();
                ((System.ComponentModel.ISupportInitialize)(this.noteHistoryGridView.MasterGridViewTemplate)).BeginInit();
                this.SuspendLayout();
                //
                // panel1
                //
                this.panel1.Controls.Add(this.noteLabel);
                this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
                this.panel1.Location = new System.Drawing.Point(0, 0);
                this.panel1.Name = "panel1";
                this.panel1.Padding = new System.Windows.Forms.Padding(3);
                this.panel1.Size = new System.Drawing.Size(400, 28);
                this.panel1.TabIndex = 0;
                //
                // noteLabel
                //
                this.noteLabel.AutoSize = true;
                this.noteLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
                this.noteLabel.Location = new System.Drawing.Point(6, 6);
                this.noteLabel.Margin = new System.Windows.Forms.Padding(3);
                this.noteLabel.Name = "noteLabel";
                this.noteLabel.Size = new System.Drawing.Size(44, 16);
                this.noteLabel.TabIndex = 1;
                this.noteLabel.Text = "Notes";
                //
                // noteHistoryGridView
                //
                this.noteHistoryGridView.BackColor = System.Drawing.SystemColors.Control;
                this.noteHistoryGridView.Cursor = System.Windows.Forms.Cursors.Default;
                this.noteHistoryGridView.Dock = System.Windows.Forms.DockStyle.Fill;
                this.noteHistoryGridView.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F);
                this.noteHistoryGridView.ForeColor = System.Drawing.SystemColors.ControlText;
                this.noteHistoryGridView.ImeMode = System.Windows.Forms.ImeMode.NoControl;
                this.noteHistoryGridView.Location = new System.Drawing.Point(0, 28);
                //
                //
                //
                this.noteHistoryGridView.MasterGridViewTemplate.AddNewRowPosition = Telerik.WinControls.UI.PinnedRowPosition.Bottom;
                this.noteHistoryGridView.MasterGridViewTemplate.AllowColumnChooser = false;
                this.noteHistoryGridView.MasterGridViewTemplate.AllowColumnReorder = false;
                this.noteHistoryGridView.MasterGridViewTemplate.AllowDeleteRow = false;
                this.noteHistoryGridView.MasterGridViewTemplate.AllowDragToGroup = false;
                this.noteHistoryGridView.MasterGridViewTemplate.AllowEditRow = false;
                this.noteHistoryGridView.MasterGridViewTemplate.AutoGenerateColumns = false;
                this.noteHistoryGridView.MasterGridViewTemplate.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill;
                gridViewTextBoxColumn1.AllowFiltering = false;
                gridViewTextBoxColumn1.AllowGroup = false;
                gridViewTextBoxColumn1.AllowHide = false;
                gridViewTextBoxColumn1.FieldAlias = "columnNote";
                gridViewTextBoxColumn1.FieldName = "Text";
                gridViewTextBoxColumn1.HeaderText = "Note";
                gridViewTextBoxColumn1.HeaderTextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
                gridViewTextBoxColumn1.MinWidth = 50;
                gridViewTextBoxColumn1.Multiline = true;
                gridViewTextBoxColumn1.UniqueName = "columnNote";
                gridViewTextBoxColumn1.Width = 215;
                gridViewTextBoxColumn1.WrapText = true;
                gridViewDateTimeColumn1.AllowFiltering = false;
                gridViewDateTimeColumn1.AllowGroup = false;
                gridViewDateTimeColumn1.AllowHide = false;
                gridViewDateTimeColumn1.DataType = typeof(System.DateTime);
                gridViewDateTimeColumn1.FieldAlias = "EntryDate";
                gridViewDateTimeColumn1.FieldName = "EntryDate";
                gridViewDateTimeColumn1.HeaderText = "Entry Date";
                gridViewDateTimeColumn1.HeaderTextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
                gridViewDateTimeColumn1.MinWidth = 50;
                gridViewDateTimeColumn1.ReadOnly = true;
                gridViewDateTimeColumn1.UniqueName = "columnDate";
                gridViewDateTimeColumn1.Width = 215;
                gridViewTextBoxColumn2.AllowFiltering = false;
                gridViewTextBoxColumn2.AllowGroup = false;
                gridViewTextBoxColumn2.AllowHide = false;
                gridViewTextBoxColumn2.FieldAlias = "EntryUsername";
                gridViewTextBoxColumn2.FieldName = "EntryUsername";
                gridViewTextBoxColumn2.HeaderText = "Username";
                gridViewTextBoxColumn2.HeaderTextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
                gridViewTextBoxColumn2.MinWidth = 50;
                gridViewTextBoxColumn2.ReadOnly = true;
                gridViewTextBoxColumn2.UniqueName = "columnUsername";
                gridViewTextBoxColumn2.Width = 215;
                this.noteHistoryGridView.MasterGridViewTemplate.Columns.Add(gridViewTextBoxColumn1);
                this.noteHistoryGridView.MasterGridViewTemplate.Columns.Add(gridViewDateTimeColumn1);
                this.noteHistoryGridView.MasterGridViewTemplate.Columns.Add(gridViewTextBoxColumn2);
                this.noteHistoryGridView.MasterGridViewTemplate.EnableGrouping = false;
                this.noteHistoryGridView.MasterGridViewTemplate.ShowRowHeaderColumn = false;
                gridSortField1.FieldAlias = "columnDate";
                gridSortField1.FieldName = "columnDate";
                this.noteHistoryGridView.MasterGridViewTemplate.SortExpressions.Add(gridSortField1);
                this.noteHistoryGridView.Name = "noteHistoryGridView";
                this.noteHistoryGridView.RightToLeft = System.Windows.Forms.RightToLeft.No;
                this.noteHistoryGridView.SelectionMode = Telerik.WinControls.UI.GridViewSelectionMode.CellSelect;
                this.noteHistoryGridView.ShowGroupPanel = false;
                this.noteHistoryGridView.Size = new System.Drawing.Size(400, 122);
                this.noteHistoryGridView.TabIndex = 1;
                this.noteHistoryGridView.ThemeName = "ControlDefault";
                this.noteHistoryGridView.CellValueChanged += new Telerik.WinControls.UI.GridViewCellEventHandler(this.noteHistoryGridView_CellValueChanged);
                //
                // NoteHistoryControl
                //
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.Controls.Add(this.noteHistoryGridView);
                this.Controls.Add(this.panel1);
                this.MinimumSize = new System.Drawing.Size(350, 125);
                this.Name = "NoteHistoryControl";
                this.Size = new System.Drawing.Size(400, 150);
                this.panel1.ResumeLayout(false);
                this.panel1.PerformLayout();
                ((System.ComponentModel.ISupportInitialize)(this.noteHistoryGridView.MasterGridViewTemplate)).EndInit();
                ((System.ComponentModel.ISupportInitialize)(this.noteHistoryGridView)).EndInit();
                this.ResumeLayout(false);
                this.PerformLayout();
     
            }

  2. Xiaoyang
    Xiaoyang avatar
    1 posts
    Member since:
    Mar 2012

    Posted 23 May 2012 Link to this post

    I have same problem related with add new row to the GridView. The Exception is as following" RadListSource need a parameterless Constructor for ....... "

  3. Nikolay
    Admin
    Nikolay avatar
    1805 posts

    Posted 23 May 2012 Link to this post

    Hi Tony,

    By the provided code snippet I can conclude that you are using quite an old version of RadControls for WinForms - a version prior to Q2 2010. I would strongly recommend updating to the latest version where many issues have been addressed and many new features have been introduced.

    Just in case, I tested the described scenario with Q1 2010 SP2 (v2010.1.10.504), but I was not able to reproduce the issue on top of the provided snippet. I also tried the case with our latest release which also did not lead to the issue. There is a piece of your code snippet, however, that I found interesting. When you are changing the value of the Text cell, you are hiding the "Click here to add a new row" row. I am not sure why this is done, but this may make you think that your submitted row covers the "Click here to add a new row" row. Please describe the desired scenario in detail, so that I can provide you with an adequate answer of what you can use and how. I am attaching a sample project based on your code snippet and a movie which demonstrates that I do not get the described behavior on my side with version Q1 2010 SP2.

    Even if we manage to reproduce the issue, however, by its description I can suppose that we will not be able to provide a workaround for it. This is why I recommend upgrading. I am also attaching a version of your sample project that works with our latest release Q1 2012 SP1. A movie of the behavior of that project is also attached. You can watch the movies in a web browser with Flash plug-in installed.

    I hope this helps.

    All the best,
    Nikolay
    the Telerik team
    RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
  4. Felipe
    Felipe avatar
    1 posts
    Member since:
    Aug 2011

    Posted 26 Jun 2013 Link to this post

    Good morning, I had the same problem with the old radgridview.
    Was populating the grid with a list saved in a file.
    I solved the problem by deleting the file and creating a new one.

    Hope this helps.
Back to Top