I am trying to display data from my Firestore in a data grid. I can return all rows if I do it in a ListView, but I really need this to be in a datagrid. I am also able to return one row using the code below. I have tried using a list collection and an observable collection, both seem to return one row aswell.
async void GetFurtherWorksApp()
{
string path = AppDomain.CurrentDomain.BaseDirectory @"cloudfire.json";
Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", path);
database = FirestoreDb.Create("engineer-app");
Query DOC = database.Collection("further_works");
QuerySnapshot snap = await DOC.GetSnapshotAsync();
foreach (DocumentSnapshot docsnap in snap.Documents)
{
FurtherWorks job = docsnap.ConvertTo<FurtherWorks>();
//FurtherWorksList.Items.Add( new { docsnap.Id, job.company, job.cost, job.jobnumber, job.jobstatus, job.partsreq, job.timespent, job.timesreq });
//FurtherWorksList.Items.Add(new { Col1 = docsnap.Id, Col2 = job.company, Col3 = job.cost, Col4 = job.jobstatus, Col5 = job.partsreq, Col6 = job.timespent, Col7 = job.timereq });
//FurtherWorksList.Columns.Add( Col1 = docsnap.Id, Col2 = job.company, Col3 = job.cost, Col4 = job.jobstatus, Col5 = job.partsreq, Col6 = job.timespent, Col7 = job.timereq );
ObservableCollection<FurtherWorks> items = new ObservableCollection<FurtherWorks>();
items.Add(new FurtherWorks { jobnumber = job.jobnumber, company = job.company, cost = job.cost });
FurtherWorksList.ItemsSource = items;
}
}
CodePudding user response:
Need to save in collection first move outside of forereach loop as well as ItemSource like this.
ObservableCollection<FurtherWorks> items = new ObservableCollection<FurtherWorks>();
foreach (DocumentSnapshot docsnap in snap.Documents)
{
FurtherWorks job = docsnap.ConvertTo<FurtherWorks>();
items.Add(new FurtherWorks { jobnumber = job.jobnumber, company = job.company, cost = job.cost });
}
FurtherWorksList.ItemsSource = items;
