简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM