sandra
sandra

Reputation: 987

Extract information from datagrid in wpf

I'm new to WPF. I have a DataGrid with number of rows and columns. I need to extract the information in each row for each column; how can I do this? Pay attention that I need the information of all rows for all columns, not a selected row.

I populated the DataGrid dynamically along these lines:

public class person
{
    public string name { get; set; }
    public string lastName { get; set; }
}

List<person> persons = new List<person>();
persons.Add(new person() { name = "john", lastName = "brown" });
persons.Add(new person() { name = "polly", lastName = "parker" });
persons.Add(new person() { name = "ann", lastName = "parker" });
persons.Add(new person() { name = "rebecca", lastName = "moosavian" });

dataGrid1.ItemsSource = persons;

And now I need to retrieve the name and lastName properties from this DataGrid after editing.

Upvotes: 0

Views: 558

Answers (1)

Dean Kuga
Dean Kuga

Reputation: 12131

How did you populate your data gird?

You must have some data source bound to your data grid (this is typically an ObservableCollection of CLR objects or some other type of collection)... your data is there, there is no need to extract anything.

The bottom line is that a data grid must have a data source, the data you see in the data grid is there and no extraction is necessary.

Upvotes: 1

Related Questions