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

[Solved] teleric grid view row delete

4 Answers 295 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.
Nishad Pillai
Top achievements
Rank 1
Nishad Pillai asked on 21 Oct 2009, 09:06 AM
Like the insert key functionality to insert new row in teleric gridview  ,is there any functionality to invoke the delete key on a teleric grid view row in silverlight instead of the context menu.Expect for a postive reply.
Thanks in advance

4 Answers, 1 is accepted

Sort by
0
Jax
Top achievements
Rank 2
answered on 21 Oct 2009, 02:32 PM
Handle the KeyUp event on the grid, and do the delete action there:

private void Grid_KeyUp(object sender, KeyEventArgs e)
{
//if the user presses the delete button, then delete the currently selected records
if (e.Key == Key.Delete)
{
//psuedocode...
Grid.Items.Remove(Grid.SelectedItem);
return;
}
}


0
Nishad Pillai
Top achievements
Rank 1
answered on 22 Oct 2009, 06:06 AM
thanks for your reply jax.But to get the keyup event we have to click in the cell.I need to get the event after selecting the entire row and pressing the delete button.I checked with key up event for the row,it wiil not get fired.
0
sreeraj
Top achievements
Rank 2
answered on 13 Jan 2010, 02:37 PM
Hi Nishad,
Me too facing the same issue . I am surprised to see why this basic feature is not supported by telerik.
The grid is not firing key events until we do it at the cell level.
Regards
Sreeraj
0
Pavel Pavlov
Telerik team
answered on 15 Jan 2010, 09:46 AM
Hi guys,

I believe you may use the following code snippet. RadGridView here is bound to a List<Person> collection.

If you bind to a collection capable of change notifications ( e.g. ObservableCollection) you may ommit the .Rebind() call.

public partial class MainPage : UserControl
    {
        public MainPage()
        {
  
            InitializeComponent();
            this.RadGridView1.ItemsSource = Person.GetSampleListOfPersons();
            this.AddHandler(UIElement.KeyDownEvent, new KeyEventHandler(MouseDownOnCell), true);
        }
  
        private void MouseDownOnCell(object sender, KeyEventArgs args)
        {
            if (args.Key == Key.Delete && this.RadGridView1.SelectedItem!= null)
            {
                ((List<Person>)this.RadGridView1.ItemsSource).Remove((Person)this.RadGridView1.SelectedItem);
                this.RadGridView1.Rebind();
            }
        }
    }

All the best,
Pavel Pavlov
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.
Tags
GridView
Asked by
Nishad Pillai
Top achievements
Rank 1
Answers by
Jax
Top achievements
Rank 2
Nishad Pillai
Top achievements
Rank 1
sreeraj
Top achievements
Rank 2
Pavel Pavlov
Telerik team
Share this question
or