Home Forums WPF controls Xceed DataGrid for WPF How To Delete Rows In DataGrid

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #22053 |

    Hello,

    Can anyone please help me , how to delete rows in datagrid?

    I have Invoked KeyDown event of Datagrid Control.
    protected void DataGridControl_KeyDown(object sender, RoutedEventArgs re)
    {
    if ((re as System.Windows.Input.KeyEventArgs).Key == Key.Delete)
    {
    myDataGrid.SelectedItems.Remove(myDataGrid.SelectedItems);
    }
    }

    But Unfortunately it is not working. Am I doing anything wrong?

    Thanks in Advance,
    Debkumar

    Imported from legacy forums. Posted by debkumar (had 8502 views)

    Xceed Support
    Member
    Post count: 5658

    Hi Debkumar,

    Deletion is currently not handled by the DataGridControl, you can refer to <a href=”http://forums.xceed.com/forums/ShowPost.aspx?PostID=5799″>this post</a> about this topic.

    Concerning your sample code, DataGridControl.SelectedItems represents user selection in the DataGridControl and removing items from this collection will simply change the current user selection.

    What you wish to do is the call the “remove” method on your data source (what was assigned to the ItemsSource property).

    Let me know if you have problems with that.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 443 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi Marcus,

    Thanks a Lot.

    Warm Regards,
    Debkumar

    Imported from legacy forums. Posted by debkumar (had 389 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi,

    Please consier row delete functionality to be a high priority.

    Thanks,
    Darrel

    Imported from legacy forums. Posted by Darrel (had 416 views)

    Xceed Support
    Member
    Post count: 5658

    Hi Darrel,

    Can you provide specific deletion requirements which would not be addressed by this post or the post referred (just so we can update the feature requirements).

    Thanks

    Imported from legacy forums. Posted by Marcus [Xceed] (had 446 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi,

    I would like to see the Delete functionality to be included in the grid:
    1. Select one or more rows, press the delete key and the rows get deleted.
    2. Configuration controls to enable/disable updating and deleting of rows (i.e. AllowUpdate, AllowDelete).

    I would consider the previous posts to be a workaround to something that is expected in a grid control.

    Overall, I’m very happy with the grid.

    Thanks,
    Darrel

    That said, here is some code to handle delete when the grid is unbound and the underlying data is based on the Items collection (i.e. ItemsSource is null):

    void dataGridControl_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
    {
    switch (e.Key)
    {
    case System.Windows.Input.Key.Delete:
    HandleDeleteRows(sender as Xceed.Wpf.DataGrid.DataGridControl);
    break;
    default:
    break;
    }
    }

    /// <summary>
    /// Handle Delete Rows
    /// </summary>
    private void HandleDeleteRows(Xceed.Wpf.DataGrid.DataGridControl dataGridControl)
    {
    if (dataGridControl.SelectedItems.Count > 0)
    {
    ItemCollection itemCollection = dataGridControl.Items as ItemCollection;
    if (itemCollection != null)
    {
    foreach (String[] items in dataGridControl.SelectedItems)
    {
    itemCollection.Remove(items);
    }
    dataGridControl.SelectedItems.Clear();
    dataGridControl.UpdateLayout();
    }
    }
    }

    Imported from legacy forums. Posted by Darrel (had 704 views)

    Xceed Support
    Member
    Post count: 5658

    Thanks for the feedback!

    Imported from legacy forums. Posted by Marcus [Xceed] (had 369 views)

    User (Old forums)
    Member
    Post count: 23064

    I would completely agree with the other posters that this is a very high priority. In my view, the grid is incomplete without the delete functionality. I just wasted 30 minutes trying to find the delete functionality in the docs and samples, only to finally find out there is no way by reading this forum.

    Imported from legacy forums. Posted by William (had 577 views)

    User (Old forums)
    Member
    Post count: 23064

    I wish to add my vote to having row deletion built it, especially if this is to be used as an alternative to the Windows Forms DataGridView which does have it built in.

    Imported from legacy forums. Posted by Alan (had 492 views)

    User (Old forums)
    Member
    Post count: 23064

    Has the delete functionality when ItemSource is not null been released?

    Imported from legacy forums. Posted by Adam (had 423 views)

    Xceed Support
    Member
    Post count: 5658

    No, deletion still needs to be handled as per you particular requirements.

    Imported from legacy forums. Posted by Marcus [Xceed] (had 8654 views)

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.