This is a migrated thread and some comments may be shown as answers.

Enable/Disable RadGridView's Row with CheckBoxes

9 Answers 730 Views
GridView
This is a migrated thread and some comments may be shown as answers.
EMRE ANDIC
Top achievements
Rank 1
EMRE ANDIC asked on 06 Apr 2010, 01:54 PM
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.

9 Answers, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 09 Apr 2010, 09:41 AM
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.
0
EMRE ANDIC
Top achievements
Rank 1
answered on 12 Apr 2010, 07:45 AM
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.   
0
Martin Vasilev
Telerik team
answered on 14 Apr 2010, 05:25 PM
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.
0
Srilakshmi
Top achievements
Rank 1
answered on 01 Nov 2010, 01:14 PM
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.
0
Martin Vasilev
Telerik team
answered on 04 Nov 2010, 03:42 PM
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
0
Srilakshmi
Top achievements
Rank 1
answered on 09 Nov 2010, 06:45 AM
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.
0
Emanuel Varga
Top achievements
Rank 1
answered on 09 Nov 2010, 09:31 AM
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

0
Avinash
Top achievements
Rank 1
answered on 17 Sep 2012, 07:41 AM
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
0
Nikolay
Telerik team
answered on 19 Sep 2012, 03:21 PM
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 >>
Tags
GridView
Asked by
EMRE ANDIC
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
EMRE ANDIC
Top achievements
Rank 1
Srilakshmi
Top achievements
Rank 1
Emanuel Varga
Top achievements
Rank 1
Avinash
Top achievements
Rank 1
Nikolay
Telerik team
Share this question
or