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

Disable the cells based on the value in other column.

2 Answers 226 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Subh
Top achievements
Rank 1
Subh asked on 24 Sep 2009, 08:32 AM
I have three columns "Column1","Column2","Column3". Based on the value in "Column1" the "Column2" and "Column3" should be disabled or enabled. How can this be implemeneted?

Thanks in advance.

2 Answers, 1 is accepted

Sort by
0
Robert
Top achievements
Rank 1
answered on 25 Sep 2009, 04:08 PM
Hey Subh,

You can prevent the user from editing a cell using the CellBeginEdit event. Here is a quick example:

        private void radGridView1_CellBeginEdit(object sender, Telerik.WinControls.UI.GridViewCellCancelEventArgs e) 
        { 
            if (radGridView1.Columns[e.ColumnIndex].FieldAlias == "ItemID"
            { 
                if (((int)radGridView1.Rows[e.RowIndex].Cells[0].Value) > 10) 
                    e.Cancel = true
            } 
        } 

- Robert
0
Accepted
Jack
Telerik team
answered on 26 Sep 2009, 06:15 AM
Hi Subh,

I suppose that you want to disable the editing of specific cell. If this is the case, you can handle CellBeginEdit event. Please consider the sample below:

void radGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e) 
    GridViewDataColumn column = (GridViewDataColumn)this.radGridView1.CurrentColumn; 
    if ((column.UniqueName == "Column2" || column.UniqueName == "Column3")) 
    { 
        if ((int)this.radGridView1.CurrentRow.Cells["Column1"].Value < 10) 
        { 
            e.Cancel = true
        } 
    } 


Additionally you can change the cell appearance when handling CellFormatting event. Take a look at the following KB article for more information.

If you have any further questions, don't hesitate to ask.

Greetings,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
Subh
Top achievements
Rank 1
Answers by
Robert
Top achievements
Rank 1
Jack
Telerik team
Share this question
or