I'm using this List:
List<AssetListData> assetList = new List<AssetListData>();
Filled with data, and bind it to my RadGridView
using this code:
AssetList_GridView.ItemsSource = assetList;
And now I have a GridView
with two columns (Name
and Type
). I created a ContextMenu
in AssetList_GridView
consists of Edit
and Delete
. I need to get the value after I click the ContextMenu
but it failed. I tried this code inside the click event in ContextMenu
:
private void GridContextMenu_ItemClick(object sender, Telerik.Windows.RadRoutedEventArgs e)
{
MenuItem item = (e.OriginalSource as RadMenuItem).DataContext as MenuItem;
switch (item.Text)
{
case "Edit Asset":
var typeValue = ((assetListData)AssetList_GridView.SelectedItem).assetType;
this.AssetList_GridView.BeginEdit();
break;
case "Delete Asset":
this.AssetList_GridView.Items.Remove(this.AssetList_GridView.SelectedItem);
break;
}
}
The error from var typeValue = ((assetListData)AssetList_GridView.SelectedItem).assetType;
said that:
assetList could not be found.
Why can't I access assetList
here, but I can access it for GridView
ItemsSource
?
Is there any simple way to get value from the clicked row?