What is the best way to prevent editing of primary key column(s) in the data grid? I do not want the user to edit existing primary key column(s), however, I do want them to be able to edit the primary key column(s) when adding a new row.
Thanks for your help in advance,
James
Thanks for your help in advance,
James
7 Answers, 1 is accepted
0
James
Top achievements
Rank 1
answered on 17 Jul 2009, 03:39 PM
I forgot to mention that I am using natural primary keys vs surrogate keys (auto generated), therefore, I can not just hide the primary keys in the grid and then auto generate the keys.
0
Hi James,
Maybe the best option in this case is to handle the CellBeginEdit event. Just set the e.Cancel property to true. Here is a sample:
If you need further assistance, please write us back.
Best wishes,
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.
Maybe the best option in this case is to handle the CellBeginEdit event. Just set the e.Cancel property to true. Here is a sample:
void radGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e) |
{ |
if (((GridViewDataColumn)this.radGridView1.CurrentColumn).FieldName == "ID" |
&& this.radGridView1.CurrentRow is GridViewDataRowInfo) |
{ |
e.Cancel = true; |
} |
} |
If you need further assistance, please write us back.
Best wishes,
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
James
Top achievements
Rank 1
answered on 21 Jul 2009, 06:04 PM
Jack,
This would cancel the edit even if you are entering data on a new row for the ID column. I need the user to be able to enter a value for the ID column on a new row, and not allow edits on the ID column for an existing row.
Thanks,
James
This would cancel the edit even if you are entering data on a new row for the ID column. I need the user to be able to enter a value for the ID column on a new row, and not allow edits on the ID column for an existing row.
Thanks,
James
0
Hello James,
This code will work with our latest release. I didn't noticed that you are using an older version. I recommend that you try our latest release. It contains many new features and improvements and we will appreciate your feedback.
You should change a little the condition when using a previous version of RadControls. Here is the modified code:
I hope this helps. Should you have any other questions, feel free to ask.
Regards,
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.
This code will work with our latest release. I didn't noticed that you are using an older version. I recommend that you try our latest release. It contains many new features and improvements and we will appreciate your feedback.
You should change a little the condition when using a previous version of RadControls. Here is the modified code:
void radGridView1_CellBeginEdit(object sender, GridViewCellCancelEventArgs e) |
{ |
if (((GridViewDataColumn)this.radGridView1.CurrentColumn).FieldName == "ID" |
&& !(this.radGridView1.CurrentRow is GridViewNewRowInfo)) |
{ |
e.Cancel = true; |
} |
} |
I hope this helps. Should you have any other questions, feel free to ask.
Regards,
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
James
Top achievements
Rank 1
answered on 22 Jul 2009, 09:46 PM
Jack,
That worked great, thanks for your help. I converted the C# code to VB using Telerik's code converter (by the way another fine piece of work from Telerik). Just click the link at the bottom of the Community page on Telerik's web site to run the code converter.
Thanks very much for your help,
James
That worked great, thanks for your help. I converted the C# code to VB using Telerik's code converter (by the way another fine piece of work from Telerik). Just click the link at the bottom of the Community page on Telerik's web site to run the code converter.
Sub radGridView1_CellBeginEdit(sender As Object, e As |
GridViewCellCancelEventArgs)<BR> If |
(DirectCast(Me.radGridView1.CurrentColumn, GridViewDataColumn)).FieldName = "ID" |
AndAlso Not (TypeOf Me.radGridView1.CurrentRow Is GridViewNewRowInfo) |
Then<BR> e.Cancel = True<BR> End If<BR>End Sub |
Thanks very much for your help,
James
0
James
Top achievements
Rank 1
answered on 22 Jul 2009, 09:50 PM
Sorry about the code formatting, I obviously do not know how to use the code formatting tool.
James
James
0
James, I am glad to hear that the solution worked for you. If you have any other questions, I will be glad to help.
Kind regards,
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.
Kind regards,
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.