Wednesday, 28 November 2012

Telerik Silverlight GridView click events


// Single click
this.TradesGrid.SelectionChanged += TradesGridSelectionChanged;

// Double click
this.TradesGrid.AddHandler(GridViewCellBase.CellDoubleClickEvent,
new EventHandler<RadRoutedEventArgs>(OnCellDoubleClick), true);

......

void TradesGridSelectionChanged(object sender, SelectionChangeEventArgs e)
{
if (e.AddedItems.Count == 0) return;

var trade = e.AddedItems[0] as Trade;
if (trade == null) return;

var vm = DataContext as ViewModel;
if (vm == null) return;

vm.OpenTradeForDocumenting(trade);
}

private void OnCellDoubleClick(object sender, RadRoutedEventArgs e)
{
var cell = e.Source as GridViewCell;
if (cell == null) return;

var row = cell.ParentRow as GridViewRow;
if (row == null) return;

var trade = row.DataContext as Trade;
if (trade == null) return;

var vm = DataContext as ViewModel;
if (vm == null) return;

vm.OpenTradeForDocumenting(trade);
}

2 comments: