This question is locked. New answers and comments are not allowed.
Hi
I think I'm missing something easy, but could not find a solution. I'm working on a grid twoway binded to an ObservableList, and I need to implement some basic functions on the cells: cut, copy, paste, delete, move and so on. While copy and paste are working easy since the last update, I cannot find a way to implement the delete function on cells only.
What I'd like:
- respond to delete key on keyboard, or context menu command
- delete the content of all the selected cells
What I'm doing:
cell.CommitEdit() launch the CellEditEnded event, so I can check that the cell new value will be "", and that the operation is Commit, but when cell.CommitEdit() returns, the cell value is resetted to the old one (that means, no delete is done) even if "t" is true.
I could try to modify the original item on the observable list, but this doesn't look very "twoway binded" to me.
Any hints on how to solve?
Thanks a lot.
I think I'm missing something easy, but could not find a solution. I'm working on a grid twoway binded to an ObservableList, and I need to implement some basic functions on the cells: cut, copy, paste, delete, move and so on. While copy and paste are working easy since the last update, I cannot find a way to implement the delete function on cells only.
What I'd like:
- respond to delete key on keyboard, or context menu command
- delete the content of all the selected cells
What I'm doing:
private void RadContextMenuItemClick(object sender, Telerik.Windows.RadRoutedEventArgs e){ RadContextMenu menu = (RadContextMenu)sender; RadMenuItem clickedItem = e.OriginalSource as RadMenuItem; GridViewRow row = menu.GetClickedElement<GridViewRow>(); if (clickedItem != null && row != null) { switch (clickedItem.Name) { case "rmiDeleteRow": rgvIsolateLookup.Items.Remove(row.Item); break; case "rmiDeleteCell": var cells = rgvIsolateLookup.ChildrenOfType<GridViewCell>().Where(c => c.IsSelected); foreach (GridViewCell cell in cells) { cell.BeginEdit(); cell.Value = ""; // i tried with cell.Content = "" too, no success bool t = cell.CommitEdit(); } break; } }}
<UserControl x:Class="DocumentManager.Panels.IsolateLookup.pnlIsolateLookup" mc:Ignorable="d" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" xmlns:telerikGrid="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView" d:DesignHeight="600" d:DesignWidth="800" Loaded="UserControlLoaded"> <Grid x:Name="LayoutRoot" Background="White"> <Grid.RowDefinitions> <RowDefinition Height="42"/> <RowDefinition /> </Grid.RowDefinitions> <StackPanel Grid.Row="0" Orientation="Horizontal" HorizontalAlignment="Center"> <Button x:Name="cmdNewRow" Content="New Row" Height="25" Click="CmdNewRowClick"></Button> <Button x:Name="cmdNewRowCopySelectedRow" Content="New Row from Selected Row" Height="25" Margin="10,0,0,0" Click="CmdNewRowCopySelectedRowClick"></Button> <Button x:Name="cmdPasteNew" Content="Paste New" Height="25" Margin="10,0,0,0" Click="CmdPasteNewClick"></Button> <Button x:Name="cmdPasteAppend" Content="Paste Append" Height="25" Margin="10,0,0,0" Click="CmdPasteAppendClick"></Button> </StackPanel> <telerik:RadGridView Grid.Row="1" HorizontalAlignment="Stretch" Margin="2,0,0,0" Name="rgvIsolateLookup" VerticalAlignment="Stretch" ItemsSource="{Binding Mode=TwoWay, UpdateSourceTrigger=Default, Path=DataContext, ElementName=rgvIsolateLookup}" Pasting="RgvIsolateLookupPasting" PastingCellClipboardContent="RgvIsolateLookupPastingCellClipboardContent" Copying="RgvIsolateLookupCopying" CopyingCellClipboardContent="RgvIsolateLookupCopyingCellClipboardContent" SelectionUnit="Cell" SelectionMode="Extended" IsSynchronizedWithCurrentItem="True" CellEditEnded="rgvIsolateLookup_CellEditEnded"> <telerik:RadContextMenu.ContextMenu> <telerik:RadContextMenu Opened="RadContextMenuOpened" ItemClick="RadContextMenuItemClick"> <telerik:RadMenuItem Header="Cut"/> <telerik:RadMenuItem Header="Copy" Command="telerikGrid:RadGridViewCommands.Copy" CommandTarget="{Binding ElementName=rgvIsolateLookup}"/> <telerik:RadMenuItem Header="Paste" Command="telerikGrid:RadGridViewCommands.Paste" CommandTarget="{Binding ElementName=rgvIsolateLookup}"/> <telerik:RadMenuItem IsSeparator="True" /> <telerik:RadMenuItem Header="Delete row" Name ="rmiDeleteRow"/> <telerik:RadMenuItem Header="Delete cell" Name ="rmiDeleteCell"/> </telerik:RadContextMenu> </telerik:RadContextMenu.ContextMenu> </telerik:RadGridView> </Grid></UserControl>cell.CommitEdit() launch the CellEditEnded event, so I can check that the cell new value will be "", and that the operation is Commit, but when cell.CommitEdit() returns, the cell value is resetted to the old one (that means, no delete is done) even if "t" is true.
I could try to modify the original item on the observable list, but this doesn't look very "twoway binded" to me.
Any hints on how to solve?
Thanks a lot.