Reputation: 39
I have this DataGrid
:
I get the data from SQL like this:
SqlDataAdapter dataAdapter = new SqlDataAdapter(command);
DataTable dt = new DataTable();
dataAdapter.Fill(dt);
Datagrid.ItemsSource = dt.DefaultView;
How can I get all values of the column "ParaXML" from the DataGrid
?
Thanks in advance.
Upvotes: 0
Views: 903
Reputation: 22089
The values come from a database. I have to check every value of this column
Instead of trying to get all column values from the DataGrid
, access the DataTable
directly in your code. As you did not provide information on that, I assume that the column data type is string
and the column ID is ParaXML
. If it is different in your code, please adapt the following samples.
foreach(DataRow row in dt.Rows)
{
var columnValue = (string)row["ParaXML"];
// ...do something with the column value.
}
If you want to get all column values as a list instead, you can do it like above in a loop or using Linq.
var paraXmls = new List<string>();
foreach(DataRow row in dt.Rows)
paraXMLs.Add((string)row["ParaXML"]);
var paraXmls = dt.AsEnumerable().Select(row => row.Field<string>("ParaXML")).ToList();
Upvotes: 1