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

Cell Read Only

12 Answers 510 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Erik
Top achievements
Rank 1
Erik asked on 03 Aug 2007, 02:17 AM
Is it possible to make the individual cell read only?
Thanks

12 Answers, 1 is accepted

Sort by
0
Dwight
Telerik team
answered on 03 Aug 2007, 10:18 AM
Hello eriksurya,

We are still working on the grid API. Up to the moment such functionality. We can suggest a workaround:

protected override OnLoad(EventArgs e)   
    base.OnLoad(e); 
    radGridView1.CurrentCellChanged +=new Telerik.WinControls.UI.CurrentCellChangedEventHandler(radGridView1_CurrentCellChanged); 
 
private void radGridView1_CurrentCellChanged(object sender, Telerik.WinControls.UI.CurrentCellChangedEventArgs e) 
    if ((int)radGridView1.CurrentCell.Value == 3) 
        radGridView1.CurrentCell.ColumnInfo.ReadOnly = true
    else 
        radGridView1.CurrentCell.ColumnInfo.ReadOnly = false

I hope that will help you continue with your project. In the future releases we will provide better ways to prevent cells from editing.

If you have other troubles, we will be glad to help you.

Regards,
Evtim
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
kilhoffer
Top achievements
Rank 1
answered on 23 Jul 2008, 03:47 AM
Is there a way to make a row readonly? I need certain rows to be readonly based on the content of one of the cells.

Thanks...
0
Jack
Telerik team
answered on 23 Jul 2008, 01:29 PM
Hi Anthony,

Thank you for contacting us.

I suggest you process the CellBeginEdit event. Consider the code snippet below:

void radGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e) 
    if ((int)this.radGridView1.CurrentRow.Cells[2].Value == 3) 
    { 
        e.Cancel = true
    } 


I hope this helps. Do not hesitate to write me if you have other questions.

Kind regards,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
ertan
Top achievements
Rank 1
answered on 24 Mar 2009, 04:38 PM
Was this problem resolved ?
My telerik version is "2009.1.9.311".
0
Jack
Telerik team
answered on 24 Mar 2009, 06:19 PM
Hello ertan,

This is not a problem. The best practice is to process the CellBeginEdit event to prevent a cell from being changed, as described in the previous post.
 
 
Kind regards,
Jack
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Zensell
Top achievements
Rank 1
answered on 11 Aug 2009, 01:03 PM
It's working fine with Q1 2009 SP1 but it is not working with Q2 2009 SP1 for GridViewCheckBoxColumns. Is there a workaround for this?
0
Jack
Telerik team
answered on 11 Aug 2009, 01:34 PM
Hello Zensell Zensell,

Yes, you should handle ValueChanging event in this case. Please consider the code snippet below:

void radGridView1_ValueChanging(object sender, ValueChangingEventArgs e) 
    if (sender is RadCheckBoxEditor) 
    { 
        e.Cancel = true
    } 

We will address the issue in our next release. Should you have any other questions, don't hesitate to contact us.

Greetings,
Jack
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Marc-Andre
Top achievements
Rank 1
answered on 28 Sep 2009, 03:16 PM
so from what I understand there's no way to set a single cell read-only? In my application, some cell within the column can or cannot be edited depending on the product type so I cannot set the entire column read-only. Also I need to know if the cell is read-only in order to make extra calculation.

Is there a way to accomplish this with 2009.2.9.729?

Thanks
0
Jack
Telerik team
answered on 29 Sep 2009, 12:03 PM
Hi Marc-Andre,

You can make a single cell read-only by handling CellBeginEdit event. Here is a sample:

void radGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e) 
    if (((GridViewDataColumn)this.radGridView1.CurrentColumn).UniqueName == "Value" && 
        (int)this.radGridView1.CurrentRow.Cells[0].Value > 10) 
    { 
        e.Cancel = true
    } 

However, there is no way to use the read-only state of the cell for calculations. You can use the cell values instead.

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.
0
Marc-Andre
Top achievements
Rank 1
answered on 29 Sep 2009, 12:30 PM
Thanks for the reply, if you read my post I can't simply use what you mention because I need to know if a cell is currently read-only or not. Using the BeginEdit would only cancel any data sent from the user. Since you can set the column property to read-only, I do not see the point of using the BeginEdit event to prevent the user from modifying the value in the cell.

Is there another way?
0
Jack
Telerik team
answered on 30 Sep 2009, 11:36 AM
Hello Marc-Andre,

Maybe I did not understand your question correctly. GridViewColumn.ReadOnly property makes entire column read-only. However, when you want to make a single cell read-only, you have to use CellBeginEdit event. There is no read-only property for grid cells. I assume that the read-only state of the cell depends on some condition. If so, you can calculate this condition when needed (e.g when processing CellBeginEdit event).

If this doesn't help, please describe the desired behavior in detail and I will be glad to assist you further. I am looking forward to your reply.

Sincerely yours,
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.
0
lucerias
Top achievements
Rank 1
answered on 09 Nov 2011, 12:38 PM

I want to make a single cell readonly = false so that it can be edited.
What i want to achieve is something like this. I have three columns, first is CustomerID, second is CustomerAddress, last is Checkbox.

All columns are in readonly.
Whatever user tick on the checkbox, customeraddress must be editable.

I have got the row already but not able to set CustomerAddress to be editable.

My xaml code is shown as below. SilverLight version is 4.

<telerik:GridViewDataColumn Header="Customer address" DataMemberBinding="{Binding CustomerAddress, Mode=TwoWay}" IsReadOnly="True" >
    <telerik:GridViewDataColumn.CellTemplate>
        <DataTemplate>
            <TextBlock Text="{Binding CustomerAddress}" />
        </DataTemplate>
    </telerik:GridViewDataColumn.CellTemplate>
  
    <telerik:GridViewDataColumn.CellEditTemplate>
        <DataTemplate>
            <TextBox Text="{Binding CustomerAddress, Mode=TwoWay}"  />
        </DataTemplate>
    </telerik:GridViewDataColumn.CellEditTemplate>
</telerik:GridViewDataColumn>


My behind code is shown as below.

CheckBox chk = (CheckBox)sender; 
GridViewRow row = chk.ParentOfType<GridViewRow>();
  
row.Cells[1].IsReadOnly = False not supported.


I stuck at this for few days already. I have achieved using TextBox instead of TextBlock but the look and feel just not right.
Hence i want it to be displayed in TextBlock and edit in TextBox.

Please let me know the alternative. Thank you very much.

Tags
GridView
Asked by
Erik
Top achievements
Rank 1
Answers by
Dwight
Telerik team
kilhoffer
Top achievements
Rank 1
Jack
Telerik team
ertan
Top achievements
Rank 1
Zensell
Top achievements
Rank 1
Marc-Andre
Top achievements
Rank 1
lucerias
Top achievements
Rank 1
Share this question
or