How do I keep the value in RadGridView edit mode after I've left the cell.

3 posts, 1 answers
  1. Pavel
    Pavel avatar
    22 posts
    Member since:
    Sep 2016

    Posted 26 Oct Link to this post

    I am trying to build a role access control, and have a grid with roles and bunch of checkboxes on each row. But, when I try to check multiple checkboxes, my previous check goes away. I want to be able to check multiple boxes and then hit save below.

    I think I am missing a property of a grid, so here's the entire code.Thanks!

    001.using System.ComponentModel;
    002.using System.Drawing;
    003.using System.Windows.Forms;
    004.using Telerik.WinControls.UI;
    005. 
    006.namespace TelerikWinFormsApp1
    007.{
    008.    public partial class RadForm1 : RadForm
    009.    {
    010.        public RadForm1()
    011.        {
    012.            var gridViewTextBoxColumn1 = new GridViewTextBoxColumn();
    013.            var gridViewCheckBoxColumn1 = new GridViewCheckBoxColumn();
    014.            var gridViewCheckBoxColumn2 = new GridViewCheckBoxColumn();
    015.            var gridViewCheckBoxColumn3 = new GridViewCheckBoxColumn();
    016.            var gridViewCheckBoxColumn4 = new GridViewCheckBoxColumn();
    017.            var tableViewDefinition1 = new TableViewDefinition();
    018.            radGridView1 = new RadGridView();
    019.            ((ISupportInitialize) (radGridView1)).BeginInit();
    020.            ((ISupportInitialize) (radGridView1.MasterTemplate)).BeginInit();
    021.            ((ISupportInitialize) (this)).BeginInit();
    022.            SuspendLayout();
    023.            //
    024.            // radGridView1
    025.            //
    026.            radGridView1.Dock = DockStyle.Fill;
    027.            radGridView1.Location = new Point(0, 0);
    028.            //
    029.            //
    030.            //
    031.            radGridView1.MasterTemplate.AllowAddNewRow = false;
    032.            radGridView1.MasterTemplate.AllowDeleteRow = false;
    033. 
    034.            gridViewTextBoxColumn1.FieldName = "Role";
    035.            gridViewTextBoxColumn1.HeaderText = "Role";
    036.            gridViewTextBoxColumn1.Name = "Role";
    037.            gridViewTextBoxColumn1.Width = 30;
    038. 
    039.            gridViewCheckBoxColumn1.FieldName = "Create";
    040.            gridViewCheckBoxColumn1.HeaderText = "Create";
    041.            gridViewCheckBoxColumn1.Name = "Create";
    042.            gridViewCheckBoxColumn1.Width = 56;
    043. 
    044.            gridViewCheckBoxColumn2.FieldName = "Read";
    045.            gridViewCheckBoxColumn2.HeaderText = "Read";
    046.            gridViewCheckBoxColumn2.Name = "Read";
    047.            gridViewCheckBoxColumn2.Width = 48;
    048. 
    049.            gridViewCheckBoxColumn3.FieldName = "Update";
    050.            gridViewCheckBoxColumn3.HeaderText = "Update";
    051.            gridViewCheckBoxColumn3.Name = "Update";
    052.            gridViewCheckBoxColumn3.Width = 60;
    053. 
    054.            gridViewCheckBoxColumn4.FieldName = "Delete";
    055.            gridViewCheckBoxColumn4.HeaderText = "Delete";
    056.            gridViewCheckBoxColumn4.Name = "Delete";
    057.            gridViewCheckBoxColumn4.Width = 55;
    058. 
    059.            radGridView1.MasterTemplate.Columns.AddRange(new GridViewDataColumn[] {
    060.            gridViewTextBoxColumn1,
    061.            gridViewCheckBoxColumn1,
    062.            gridViewCheckBoxColumn2,
    063.            gridViewCheckBoxColumn3,
    064.            gridViewCheckBoxColumn4});
    065. 
    066.            radGridView1.MasterTemplate.ViewDefinition = tableViewDefinition1;
    067.            radGridView1.Name = "radGridView1";
    068.            radGridView1.ShowGroupPanel = false;
    069.            radGridView1.Size = new Size(292, 270);
    070.            radGridView1.TabIndex = 0;
    071.            radGridView1.Text = "radGridView1";
    072.            //
    073.            // RadForm1
    074.            //
    075.            AutoScaleDimensions = new SizeF(6F, 13F);
    076.            AutoScaleMode = AutoScaleMode.Font;
    077.            ClientSize = new Size(292, 270);
    078.            Controls.Add(radGridView1);
    079.            Name = "RadForm1";
    080.            //
    081.            //
    082.            //
    083.            RootElement.ApplyShapeToControl = true;
    084.            Text = "RadForm1";
    085.            ((ISupportInitialize) (radGridView1.MasterTemplate)).EndInit();
    086.            ((ISupportInitialize) (radGridView1)).EndInit();
    087.            ((ISupportInitialize) (this)).EndInit();
    088.            ResumeLayout(false);
    089. 
    090. 
    091.            radGridView1.DataSource = new[]
    092.            {
    093.                new { Role = "Admin", Create = true, Read = true, Update = true, Delete = true },
    094.                new { Role = "Reader", Create = false, Read = true, Update = false, Delete = false },
    095.                new { Role = "Editor", Create = false, Read = true, Update = true, Delete = false },
    096.                new { Role = "Writer", Create = true, Read = true, Update = true, Delete = false }
    097.            };
    098.        }
    099.    }
    100.}
  2. Answer
    Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 27 Oct Link to this post

    Hi Pavel,

    Thank you for writing.

    You are binding the grid to an array of anonymous object and since these object properties cannot be changed the old value is returned. Instead using such objects you can just add the rows to the grid:
    radGridView1.Rows.Add("admin", true, true, true, true);

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

    Regards,
    Dimitar
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Pavel
    Pavel avatar
    22 posts
    Member since:
    Sep 2016

    Posted 27 Oct Link to this post

    @Dimitar, thank you! Anonymous objects will be my downfall someday :)
Back to Top