Show "Click Here to Add a New Item"

9 posts, 1 answers
  1. Simon
    Simon avatar
    32 posts
    Member since:
    Aug 2011

    Posted 07 Mar 2016 Link to this post

    Hi

    I have a grid bound to an empty dataset. When I load the form, it shows an empty row in the grid instead of showing the "Click Here to Add a New Item". As soon as I've added a row, the "Click Here to Add a New Item" row appears. How can I get it to show "Click Here to Add a New Item" at the start instead of showing an empty row?

  2. Answer
    Dimitar
    Admin
    Dimitar avatar
    2841 posts

    Posted 08 Mar 2016 Link to this post

    Hi Simon,

    Thank you for writing.

    You should just set the current row to null:
    radGridView1.CurrentRow = null;

    Let me know if you have additional questions.

    Regards,
    Dimitar
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. sebastien
    sebastien avatar
    42 posts
    Member since:
    May 2017

    Posted 13 Mar 2019 Link to this post

    I found this "problem" also and came here with a quick search.

     

    I think that this is not a correct behavior as in some of my grids users can enter an empty line, it look-alike empty, but the "False" checkboxes means something in the database. In this case, there is no difference between an empty grid (no rows) and a 1 row grid.

    See attached picture.

  4. Dimitar
    Admin
    Dimitar avatar
    2841 posts

    Posted 14 Mar 2019 Link to this post

    Hello Sebastien,

    I have tested with the latest version an a row is not added unless the user enters a value. The attached video shows how I am testing this. Am I doing something wrong? I have attached my test project as well.

    I am looking forward to your reply.

    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboard and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  5. sebastien
    sebastien avatar
    42 posts
    Member since:
    May 2017

    Posted 14 Mar 2019 in reply to Dimitar Link to this post

    I modified your project to reproduce, but cannot send it here :(

     

    How to reproduce :

    1. click on the checkbox (checking it)
    2. reclick on the checkbox for unchecking it
    3. click in the textbox (row is created then lostfocus out of the grid)
    4. select the row previously inserted (which has the checkbox checked)

    After the step 3, the just inserted (data) row is identical to the Add row (used for inserting new data) which is this my problem.

    namespace _1017278
    {
        partial class RadForm1
        {
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.ComponentModel.IContainer components = null;
     
            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }
     
            #region Windows Form Designer generated code
     
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                Telerik.WinControls.UI.GridViewTextBoxColumn gridViewTextBoxColumn1 = new Telerik.WinControls.UI.GridViewTextBoxColumn();
                Telerik.WinControls.UI.GridViewCheckBoxColumn gridViewCheckBoxColumn1 = new Telerik.WinControls.UI.GridViewCheckBoxColumn();
                Telerik.WinControls.UI.GridViewDecimalColumn gridViewDecimalColumn1 = new Telerik.WinControls.UI.GridViewDecimalColumn();
                Telerik.WinControls.UI.TableViewDefinition tableViewDefinition1 = new Telerik.WinControls.UI.TableViewDefinition();
                this.radGridView1 = new Telerik.WinControls.UI.RadGridView();
                this.radTextBox1 = new Telerik.WinControls.UI.RadTextBox();
                this.button1 = new System.Windows.Forms.Button();
                ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).BeginInit();
                ((System.ComponentModel.ISupportInitialize)(this.radGridView1.MasterTemplate)).BeginInit();
                ((System.ComponentModel.ISupportInitialize)(this.radTextBox1)).BeginInit();
                ((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
                this.SuspendLayout();
                //
                // radGridView1
                //
                this.radGridView1.Location = new System.Drawing.Point(325, 127);
                //
                //
                //
                gridViewTextBoxColumn1.HeaderText = "column1";
                gridViewTextBoxColumn1.Name = "columnId";
                gridViewTextBoxColumn1.Width = 100;
                gridViewCheckBoxColumn1.HeaderText = "column1";
                gridViewCheckBoxColumn1.Name = "columnBool";
                gridViewCheckBoxColumn1.Width = 66;
                gridViewDecimalColumn1.DataType = typeof(int);
                gridViewDecimalColumn1.DecimalPlaces = 0;
                gridViewDecimalColumn1.HeaderText = "column1";
                gridViewDecimalColumn1.Name = "columnInt";
                gridViewDecimalColumn1.Width = 51;
                this.radGridView1.MasterTemplate.Columns.AddRange(new Telerik.WinControls.UI.GridViewDataColumn[] {
                gridViewTextBoxColumn1,
                gridViewCheckBoxColumn1,
                gridViewDecimalColumn1});
                this.radGridView1.MasterTemplate.ViewDefinition = tableViewDefinition1;
                this.radGridView1.Name = "radGridView1";
                this.radGridView1.Size = new System.Drawing.Size(515, 456);
                this.radGridView1.TabIndex = 0;
                //
                // radTextBox1
                //
                this.radTextBox1.Location = new System.Drawing.Point(653, 657);
                this.radTextBox1.Name = "radTextBox1";
                this.radTextBox1.Size = new System.Drawing.Size(100, 20);
                this.radTextBox1.TabIndex = 1;
                //
                // button1
                //
                this.button1.Location = new System.Drawing.Point(151, 42);
                this.button1.Name = "button1";
                this.button1.Size = new System.Drawing.Size(75, 23);
                this.button1.TabIndex = 2;
                this.button1.Text = "button1";
                this.button1.UseVisualStyleBackColor = true;
                this.button1.Click += new System.EventHandler(this.button1_Click);
                //
                // RadForm1
                //
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(1013, 764);
                this.Controls.Add(this.button1);
                this.Controls.Add(this.radTextBox1);
                this.Controls.Add(this.radGridView1);
                this.Name = "RadForm1";
                //
                //
                //
                this.RootElement.ApplyShapeToControl = true;
                this.Text = "RadForm1";
                ((System.ComponentModel.ISupportInitialize)(this.radGridView1.MasterTemplate)).EndInit();
                ((System.ComponentModel.ISupportInitialize)(this.radGridView1)).EndInit();
                ((System.ComponentModel.ISupportInitialize)(this.radTextBox1)).EndInit();
                ((System.ComponentModel.ISupportInitialize)(this)).EndInit();
                this.ResumeLayout(false);
                this.PerformLayout();
     
            }
     
            #endregion
     
            private Telerik.WinControls.UI.RadGridView radGridView1;
            private Telerik.WinControls.UI.RadTextBox radTextBox1;
            private System.Windows.Forms.Button button1;
        }
    }
    public partial class RadForm1 : Telerik.WinControls.UI.RadForm
    {
        public RadForm1()
        {
            InitializeComponent();
     
            radGridView1.Rows.Clear();
     
            //radGridView1.AddNewRowPosition = Telerik.WinControls.UI.SystemRowPosition.Bottom;
        }
     
        private void AddRow(int i)
        {
            var rowInfo = radGridView1.Rows.AddNew();
     
            rowInfo.Cells["columnId"].Value = Guid.NewGuid();
            rowInfo.Cells["columnBool"].Value = true;
            rowInfo.Cells["columnInt"].Value = i + DateTime.Now.Second;
        }
     
        private void button1_Click(object sender, EventArgs e)
        {
            radGridView1.Rows.Clear();
            for (int i = 0; i < 5; i++)
            {
                AddRow(i);
            }
        }
    }
  6. Dimitar
    Admin
    Dimitar avatar
    2841 posts

    Posted 15 Mar 2019 Link to this post

    Hello Sebastien,

    Thank you for the code I was able to reproduce this case. Please note that until the user clicks in the checkbox in the new row all values are null, after that the cell will have a value (true/false) and you cannot reset it to null from the UI. Once there is a value in a particular cell the row will be added to the grid. This is desired by design behavior. What you can do is use the grid events and cancel the new row adding for this exact case:
    private void RadGridView1_UserAddingRow(object sender, Telerik.WinControls.UI.GridViewRowCancelEventArgs e)
    {
        var newRow = e.Rows[0] as GridViewNewRowInfo;
        if (newRow.Cells[0].Value == null && (bool)newRow.Cells[1].Value == false && newRow.Cells[2].Value == null)
        {
            e.Cancel = true;
            radGridView1.MasterView.TableAddNewRow.CancelAddNewRow();
        }
    }

    I hope this will be useful. Let me know if you have additional questions.

    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboard and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  7. sebastien
    sebastien avatar
    42 posts
    Member since:
    May 2017

    Posted 15 Mar 2019 in reply to Dimitar Link to this post

    Hi Dimitar,

     

    I am using the UserAddingRole already for inserting into our special data objects.

    I don't want to cancel it because for us the row is valid; we insert a row in our data object.

    Our problem with the grid is that this inserted line is identical to the AddRow when the grid contains any row. The user won't be able to differentiate between an empty grid and a grid with one empty row.

     

    Why not having the "Click Here to Add a New Item" shown when the grid is empty, so at all time?

     

    We think its a design flaw since the behavior is different from a "dumb & stupid" user's point of view.

  8. Dimitar
    Admin
    Dimitar avatar
    2841 posts

    Posted 18 Mar 2019 Link to this post

    Hi Sebastien,

    Ok, I see your point now. I have logged this issue on our Feedback Portal. You can track its progress, subscribe to status changes and add your comment to it here. I have also updated your Telerik Points.

    Until this is resolved you can manually set the row to null as described in my original post. 

    Should you have any other questions do not hesitate to ask.
     
    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboard and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  9. sebastien
    sebastien avatar
    42 posts
    Member since:
    May 2017

    Posted 18 Mar 2019 in reply to Dimitar Link to this post

    Thank you Dimitar
Back to Top