I am new to C# and this is completely stumping me. I have a WPF form with many textboxes that are used to to spatially represent the number of services required in each area (PropertyZone) of a map.
I can write a LINQ query that brings back all of my necessary data into a DataGrid, but I have been completely unable to access the data beyond that. I have attempted to dump the data into a DataTable, to no avail. I can see the data in the DataGrid, but I do not know how to iterate through the rows. I do not care if I use a DataGrid, DataTable, Collection or any other method to access the data. In stumbling around a Collection seems like it might be a good solution, but the use of inner joins and a count() seems to be my downfall.
There are two columns of data being produced:
Column1=PropertyZone
Column2=CountOfServicesInThatPropertyZone
I want to look at Column1 Row1 and based on this value, dump the value from Column2 Row1 into a textbox with the same name as the value in Column1 Row1 and do this for all rows in each of the two columns.
This is the LINQ query that does work, but I have been completely unable to access the data.
var query =
from o in con.ORDER_LINE_TABLEs
join p in con.PROPERTY_TABLEs on o.PropertyNumber equals p.PropertyNumber
where o.ServiceNumber == 2
group o by p.PropertyZone into g
select new { PropertyZone = g.Key, CountOfServicesInThatPropertyZone = g.Count() };
ServiceDataGrid.ItemsSource = query;
I hope this is clear.
If you want to access an item in particular, you have to run the query and store the results somewhere, for example inside a List. You can then bind the DataGrid to this same List: