w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Getting selected Item in DataGrid in WPF

Don't check in Loaded event, instead Check in selectionChanged event, also add a null check to your pers object

private void personelEntityDataGrid_SelectionChanged(object
sender, RoutedEventArgs e)
{
    PersonelEntity pers =
(PersonelEntity)personelEntityDataGrid.SelectedItem;
    if(pers != null)
    {
    NameBox.Text = pers.Name; // I get exception here
    AgeBox.Text = pers.Age.ToString();
    PhoneNumberBox.Text = pers.PhoneNumber;
    AddresBox.Text = pers.Address;
    }

}




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.