I am binding dictionary to my DataGrid. Now I want to get the selected row from the DataGrid. Here is what I tried till now.
Dictionary<int, string> dicKeyValue = new Dictionary<int, string>();
public MainWindow()
{
InitializeComponent();
dataGrid.DataContext = dicKeyValue;
dicKeyValue.Add(1, "INDIA");
dicKeyValue.Add(2, "CHINA");
dicKeyValue.Add(3, "AMERICA");
dicKeyValue.Add(4, "RUSSIA");
}
private void dataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var sample = (sender as DataGrid).SelectedItem as ******
// Here in the above line what should I write to get the values of selected row.
if (sample != null)
{
}
}
while debugging I tried this in the Immediate Window.....
((sender as DataGrid).SelectedItem)
{[8, SCAN]}
Key: 8
Value: "SCAN"
key: 8
value: "SCAN"
Now can you guys please help me how to access this...
My question may look similar to this , but in my question I want to know the correct type into which I can typecast the SelectedItem.