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

[Solved] Delete row available depending on content

3 Answers 127 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Berthold
Top achievements
Rank 1
Berthold asked on 04 Nov 2010, 09:35 AM
Hi,

delete rows should only be possible for new items - I mean not yet saved.

For this I added this row to the grid: 

 

<Controls:GridViewColumn>
<Controls:GridViewColumn.CellTemplate>
          <DataTemplate>
            <Controls3:RadButton Content="Löschen" Command="Controls:RadGridViewCommands.Delete" CommandParameter="{Binding}" 
                 Visibility="{Binding SportLeistId, Converter={StaticResource localConvertVisibility}, ConverterParameter=0}" />
                         </DataTemplate>
                     </Controls:GridViewColumn.CellTemplate>
                 </Controls:GridViewColumn>
Since SportLeistId is 0 as long as the item is not saved, the Button is visible for new items.
Unfortunately with keyboard "Del" deleting is possible even for already saved items.
I tried to prevent this with CanUserDeleteRows="false", but then my button became disable as well.

Any idea how can I solve this?
Thanks
Berthold

 

3 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 10 Nov 2010, 09:55 AM
Hi Berthold,

Please excuse me for the delayed answer.
You may prevent the deleting of the already saved items the following way :
You may subscribe to the Deleting event the following way :

this.RadGridView1.Deleting += new EventHandler<GridViewDeletingEventArgs>(playersGrid_Deleting);

inside the event handler  you may cancel the delete operation the following way :

void RadGridView1_Deleting(object sender, GridViewDeletingEventArgs e)
{
     var itemToBeDeleted = e.items[0];


    e.Cancel = true
}

Of course you will need to perform a check inside the handler whether the item is new or not e.g. by checing its ID .

Regards,
Pavel Pavlov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Arun
Top achievements
Rank 1
answered on 19 Nov 2010, 11:19 AM
How to get the instance of the row is being deleted.

I need to get the row and i need to check the value in the row with my custom validation. If the validation is sucessful then i will delete the row other wise i may cancel the event

Arun
0
Ivan Ivanov
Telerik team
answered on 19 Nov 2010, 12:17 PM
Hi Arun,

Since the Items property of GridViewDeletingEventArgs is of type IEnumerable, you can iterate through
it and apply your custom validation. For instance, let BusinessObject be the type the of business objects that you are populating the RadGridView with, you may try this approach to make a simple check (in our example - checking if the object's int ID property is odd, or even):

void testGrid_Deleting(object sender, GridViewDeletingEventArgs e)
{
        BusinessObject bObj;
        var r = e.Items.GetEnumerator();
        r.MoveNext();
        bObj = (BusinessObject)r.Current;
        if(bObj.ID % 2 == 0)
                e.Cancel = true;
}

Let us know if that is not what you want.

Sincerely,

Ivan X1
the Telerik team

Browse the videos here>> to help you get started with RadControls for Silverlight
Tags
GridView
Asked by
Berthold
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Arun
Top achievements
Rank 1
Ivan Ivanov
Telerik team
Share this question
or