Enable/Disable RadGridView's Row with CheckBoxes

10 posts, 0 answers
  1. EMRE ANDIC
    EMRE ANDIC avatar
    13 posts
    Member since:
    Jan 2010

    Posted 06 Apr 2010 Link to this post

    Hi,
    I need to know how can I enable or disable ReadOnly property of a RadGridView's row. I have CheckBox column, and I want to manage ReadOnly property of selected row with checkboxes.
  2. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 09 Apr 2010 Link to this post

    Hi EMRE ANDIC,

    Thank you for the question.

    One way to implement the described requirement is to cancel the CellBeginEdit event in order to mimic read only behavior depending on your check box column value. Please, consider the following code:
     
    void radGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e)
    {
        if (e.ColumnIndex != 0 && !CheckValue(this.radGridView1.CurrentRow.Cells[0].Value))
        {
            e.Cancel = true;
        }
    }
    private bool CheckValue(object value)
    {
        if (value is DBNull || value == null)
        {
            return false;
        }
        bool pValue;
        if (Boolean.TryParse(value.ToString(), out pValue))
        {
            return pValue;
        }
        return false;
    }

    Let me know if you have any other questions.

    Greetings,
    Martin Vasilev
    the Telerik team

    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 Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. EMRE ANDIC
    EMRE ANDIC avatar
    13 posts
    Member since:
    Jan 2010

    Posted 12 Apr 2010 Link to this post

    Hi Martin Vasilev,
    I decided to abandon checkbox event. 
    Is there another way to disable or enable a row according to any of a mouse event, because when I write e.Cancel = true/false to CellBeginEdit event, it enables or disables all rows, but I just want to effect a row at a time.   
  5. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 14 Apr 2010 Link to this post

    Hi EMRE ANDIC,

    RadGridView uses virtualization (it reuses its RowElements), so you have to use CellFormatting or CellBeginEdit to do the job. Either method needs a condition to determine if particular row should be read-only or not. That means, if you abandon the check-box column approach, you still need a flag to determine the row state. For example you can use row's Tag property for this or just add a hidden column and use its value.
     

    Sincerely yours,
    Martin Vasilev
    the Telerik team

    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 Public Issue Tracking system and vote to affect the priority of the items.
  6. Srilakshmi
    Srilakshmi avatar
    2 posts
    Member since:
    Nov 2010

    Posted 01 Nov 2010 Link to this post

    Hi,

    I am also facing the same problem.I have a radgridview with a checkbox column in it.I have 6 rad combobox in a form in which on last combobox selectedindexchange the gridview loads.
    The issue is some rows of gridview should be completely readonly while loading the grid or after immediately the grid has loaded .Please throw some light to solve this issue.

    Regards
    Luckee.
  7. Martin Vasilev
    Admin
    Martin Vasilev avatar
    1061 posts

    Posted 04 Nov 2010 Link to this post

    Hello Srilakshmi,

    Thank you for contacting us.

    As I have mentioned in my previous post, probably the most suitable way to implement the described scenario is by using RowFormatting or CellFormatting event. Just create a conditional statement there, which will determine which row should be read only and which should be not. Some examples of using Row/CellFormatting event you can find in our product documentation.

    Let me know if you have any additional questions.

    Regards,
    Martin Vasilev
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  8. Srilakshmi
    Srilakshmi avatar
    2 posts
    Member since:
    Nov 2010

    Posted 09 Nov 2010 Link to this post

    Hi Martin,

    Thanks a lot for your reply and its working.
    I have same kind of another problem with grid view.
    I am using a telerik grid view in which a column should be validated with numeric values only on key press event.
    Please help me regarding this.


    Regards
    Luckee.
  9. Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 09 Nov 2010 Link to this post

    Hello Srilakshmi ,

    Please take a look at the following example:
    using System;
    using System.ComponentModel;
    using System.Windows.Forms;
    using Telerik.WinControls.UI;
     
    public partial class Form1 : Form
    {
        private RadGridView radGridView1;
     
        public Form1()
        {
            InitializeComponent();
            this.Controls.Add(radGridView1 = new RadGridView());
            radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
            radGridView1.Dock = DockStyle.Fill;
            radGridView1.CellBeginEdit += new GridViewCellCancelEventHandler(radGridView1_CellBeginEdit);
        }
     
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            radGridView1.DataSource = new TestsCollection(10);
        }
     
        void radGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e)
        {
            if (radGridView1.Columns[e.ColumnIndex].Name == "Digits")
            {
                var editManager = sender as GridViewEditManager;
                var textBoxEditor = editManager.ActiveEditor as RadTextBoxEditor;
                if (textBoxEditor != null)
                {
                    var textBoxElement = textBoxEditor.EditorElement as RadTextBoxEditorElement;
                    textBoxElement.KeyPress += new KeyPressEventHandler(textBoxElement_KeyPress);
                }
            }
        }
     
        void textBoxElement_KeyPress(object sender, KeyPressEventArgs e)
        {
            e.Handled = !char.IsDigit(e.KeyChar);
        }
    }
     
    public class Test
    {
        public string Text
        {
            get;
            set;
        }
     
        public string Digits
        {
            get;
            set;
        }
    }
     
    public class TestsCollection : BindingList<Test>
    {
        public TestsCollection(int noItems)
        {
            for (int i = 0; i < noItems; i++)
            {
                this.Add(new Test
                {
                    Text = "Text " + i.ToString(),
                    Digits = i.ToString()
                });
            }
        }
    }

    Hope this helps, if you have any other questions or comments, please let me know,

    Best Regards,
    Emanuel Varga

  10. Avinash
    Avinash avatar
    1 posts
    Member since:
    Sep 2012

    Posted 17 Sep 2012 Link to this post

    Hi,

    I am also facing the same problem similar to that.
    In my application I am using a rad grid view and in that I am having check box column. I have added one context menu because on the right click event of the rad grid i should enable all my check boxes. And after all my check boxes are enabled, I shoud close my rows in which the check boxes are enabled by using the buuton click event. So please provide me some help in solving the issue.

    Regards,
    Avinash
  11. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 19 Sep 2012 Link to this post

    Hi Avinash,

    I am not sure that I understand your scenario and the issues that you have with it completely. Therefore, I would kindly ask you to open a new support ticket and send me a sample project which demonstrates your case. In addition, describe where exactly you are experiencing issues. Last, but not least, please share more details on the action 'close my rows' and the meaning that you put in it.

    Thank you for your cooperation. I am looking forward to receiving the details.

    Kind regards,
    Nikolay
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Back to Top
UI for WinForms is Visual Studio 2017 Ready