'How Do I Get Especific Cell Data From Selected Row From DataGrid?

I'm a Beginner on WPF / Xaml / C# and I'm struggling to do what's written in the title.

What I want to do is: My Grid has 3 Columns (ID, Name, Color) And When the user double clicks on the datagrid row, it gets the first cell data (ID) of that row, to a variable (Global.ID).

I can't figure this out since WPF doesn't have ".SelectedRow".

private void DataGridStart_MouseDoubleClick(object sender, MouseButtonEventArgs)
{
   if (DataGridStart == null ) || DataGridStart.SelectedItems == null ) return;} 
   if (DataGridStart.SelectedItems.Count == 1)
   {
       Global.ID = ***Clicked / Selected Row "ID" Cell***
       Main.Show();
       this.Close();
   }
}

Appreciate Any Help,

Thanks



Solution 1:[1]

Cast the SelectedItem property to your type with the three properties for the ID, Name and Color and then access the corresponding property, e.g.:

var selectedItem = DataGridStart.SelectedItem as YourClass;
var id = selectedItem?.ID;

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mm8