I have an editable grid that needs to have one of its cells conditionally editable. I decided that the best place to make this check would probably be the EditCommand event. My rationale was that when an item was clicked to be edited, I would grab the ID from it, and if it was greater than 0, I would grab the GridTextBoxColumnEditor for the DataKey cell and set its TextBox to Enabled = false. Below is my code snippet.
What's happening is that I'm getting an ArgumentOutOfRangeException on the line item.EditManager.GetColumnEditor("DataKey"). I figured ok, this is obviously not the right event to tap into. However, when I was in debug mode, I put a watch on item.EditManager.GetColumnEditor("IsActive") and that returned the correct GridCheckboxColumnEditor without tossing the exception. The only thing that I could tell that was different was the fact that I'm setting the ColumnEditorID for the DataKey column and not on the IsActive column (besides the obvious fact that they're different column types), so I tried taking it out and letting the BoundColumn handle it on its own, but that had the same result. Could you point me in the right direction?
Thanks,
Jared
| <telerik:RadGrid ID="coreDataEntriesGrid" runat="server" Width="700" EnableViewState="true" HorizontalAlign="Center" |
| AutoGenerateColumns="false" AllowSorting="false" OnRowDrop="CoreDataEntriesGrid_RowDrop" Skin="Web20" |
| OnNeedDataSource="CoreDataEntriesGrid_NeedDataSource" OnUpdateCommand="CoreDataEntriesGrid_UpdateCommand" |
| OnInsertCommand="CoreDataEntriesGrid_InsertCommand" OnEditCommand="CoreDataEntriesGrid_EditCommand"> |
| <MasterTableView DataKeyNames="ObjectID,DataKey,DataValue,IsActive" EditMode="InPlace" CommandItemDisplay="Top"> |
| <Columns> |
| <telerik:GridEditCommandColumn ButtonType="LinkButton" CancelText="Cancel" EditText="Edit" UpdateText="Update" /> |
| <telerik:GridBoundColumn HeaderText="Key" DataField="DataKey" ItemStyle-Width="100" |
| ColumnEditorID="dataKeyEditor" UniqueName="DataKey" /> |
| <telerik:GridBoundColumn HeaderText="Value" DataField="DataValue" ItemStyle-Width="500" |
| ColumnEditorID="dataValueEditor" UniqueName="DataValue" /> |
| <telerik:GridCheckBoxColumn HeaderText="Active" DataField="IsActive" ItemStyle-Width="50" |
| UniqueName="IsActive" /> |
| </Columns> |
| </MasterTableView> |
| <ClientSettings AllowRowsDragDrop="true"> |
| <Selecting AllowRowSelect="true" /> |
| <ClientEvents OnRowDropping="CoreDataEntriesGrid_RowDropping" /> |
| </ClientSettings> |
| </telerik:RadGrid> |
| <telerik:GridTextBoxColumnEditor ID="dataKeyEditor" runat="server" TextBoxStyle-Width="100" /> |
| <telerik:GridTextBoxColumnEditor ID="dataValueEditor" runat="server" TextBoxStyle-Width="500" /> |
| protected void CoreDataEntriesGrid_EditCommand(object source, GridCommandEventArgs e) |
| { |
| GridEditableItem item = e.Item as GridEditableItem; |
| int id = (int) item.GetDataKeyValue("ObjectID"); |
| if (id > 0) |
| { |
| (item.EditManager.GetColumnEditor("DataKey") as GridTextBoxColumnEditor).TextBoxControl.Enabled = false; |
| } |
| } |
What's happening is that I'm getting an ArgumentOutOfRangeException on the line item.EditManager.GetColumnEditor("DataKey"). I figured ok, this is obviously not the right event to tap into. However, when I was in debug mode, I put a watch on item.EditManager.GetColumnEditor("IsActive") and that returned the correct GridCheckboxColumnEditor without tossing the exception. The only thing that I could tell that was different was the fact that I'm setting the ColumnEditorID for the DataKey column and not on the IsActive column (besides the obvious fact that they're different column types), so I tried taking it out and letting the BoundColumn handle it on its own, but that had the same result. Could you point me in the right direction?
Thanks,
Jared