But want to allow insert/delete. ( where you can enter data into the insert )
I was looking at some post talking about BeginningEdit and Cancel.
But in BeginningEdit can't determine if grid is in Insert or Edit mode.
Any ideas on the best approach.
Thanks
Jim
10 Answers, 1 is accepted
<telerik:RadGridView IsReadOnlyBinding={Binding IsReadOnly}> would make each row as a whole readonly or not. If you used the columns instead you can narrow it to just certain columns - which doesnt sound like you care about.
I am not sure I want to work on the view model.
Just have a read only grid that you can delete/insert rows.
Jim
The BeginningEdit event has a e.Cancel property.
So I could cancel the edit if I knew it was an not an insert.
Now the RowEditEnded event has an e.EditOperationType Insert/Edit.
But that's not available in BeginningEdit
Any way to detemine in BeginningEdit ??
Help
Thanks
Jim
If you would like to have a ReadOnly GridView that allows Insert and Delete, then you could set all your columns to be ReadOnly.
If this is not acceptable for you, then you could set your bound properties to be not editable.
[Editable(
false
, AllowInitialValue=
true
)]
public
string
Name
{
...
}
Do any of those solutions work for your case?
Greetings,
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
I tried setting the column to isreadonly but unfortunatly when you insert a column you can't edit the contents in insert mode.
Thanks
Jim
It seems to work ,,,
From previous work I know a new row has index -1
Hence the code for beginingedit is
Dim rgv As RadGridView = DirectCast(sender, RadGridView)
Dim rowindex As Integer = rgv.Items.IndexOf(e.Row.Item)
If rowindex > -1 Then
e.Cancel = True
End If
And then you have a grid that can't be editied but you can still
1) Delete rows.
2) Insert a new row and edit this row on insertion.
Any problems with this approach ?
Thanks
Jim
Actually this code will only work when your ItemsSource is not an IList or when the ShowInsertRow=True.
You could better do it another way.
1. You will need your private variable that holds the state of the edit.
private
bool
isNewItemAdded=
false
;
2. Then on AddingNewDataItem event raised mark this bool flag:
private
void
clubsGrid_AddingNewDataItem(
object
sender, GridViewAddingNewEventArgs e)
{
isNewItemAdded =
true
;
}
3. On BeginningEdit check the flag:
private
void
clubsGrid_BeginningEdit(
object
sender, GridViewBeginningEditRoutedEventArgs e)
{
if
(!isNewItemAdded)
{
e.Cancel =
true
;
isNewItemAdded =
false
;
}
}
Please check this solution and let me know how it works for you.
All the best,
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
There are so many possible holes in either method without knowing more of the requirements. Are these "new" items always immediately commited and no longer editable? What happens if they fail validation? Can you "start" more than one new item and are they all editable until some external commit event?
You are going to have to maintain context if you insist on not wrapping your items in a vm. Does the AddingNewDataItem event give you the item it just created? If so you would be better served just storing that in a nullable object and then reseting the object to null after you can no longer edit that item. Then in your beginning edit check if the edit belongs to the item you have stored (or if its null)...if so edit it, if not cancel.
As for validation, when you press insert and go into the cell, edit it won't allow you to insert an invalid date.
So from my point of view it all looks OK.
But thanks for the different options I may need to look at those in future.
Jim