HowTo : Delete Tiles from C1TileView

ComponentOne TileView for WPF includes the C1TileView control, a panel that shows how to interactively browse through the data. It browses through the data interactively and expands and collapses the Tiles (C1TileViewItem(s)) to view more or less information. This blog discusses how one can delete the Tiles, that is, the C1TileViewItems from C1TileView in the following two ways :

  1. On pressing the 'Delete' Key
  2. On the Click of a Button placed inside the respective C1TileViewItem.

Delete Tiles on pressing the 'Delete' Key

To delete the tiles on pressing the Delete key, we need to handle the MouseDown event of C1TileView and set the focus on the clicked tile. Once the tile has focus, we need to handle the PreviewKeyDown to handle the 'Delete' key press. Here is the code for the same:


private void C1TileView_MouseDown(object sender, MouseButtonEventArgs e)  
{  
    if (e.Source.GetType() == typeof(C1TileViewItem))  
    {  
        //Get the respective TileViewItem  
        item = (C1.WPF.C1HeaderedContentControl)e.Source as C1TileViewItem;  
        item.Focus();  
    }  
}  
private void tileview_PreviewKeyDown(object sender, KeyEventArgs e)  
{  
    if (e.Key == Key.Delete)  
    {  
        //Remove the Item on the press of 'Delete' Key  
        tileview.Items.Remove(item);  
    }  
}  

Delete Tiles on the Click of a Button

Deleting tiles on click of a button is even simpler. Here is the code for the same:


private void Delete_Click(object sender, RoutedEventArgs e)  
{  
    if (((System.Windows.Controls.Primitives.ButtonBase)(e.Source)).Parent.GetType() == typeof(C1TileViewItem))  
    {  
        //Get the respective TileViewItem  
        item = ((System.Windows.Controls.Primitives.ButtonBase)(e.Source)).Parent as C1TileViewItem;  
        tileview.Items.Remove(item);  
    }  
}  

DeleteTiles Download Sample CS Download Sample VB

GrapeCity

GrapeCity Developer Tools
comments powered by Disqus