У меня есть IList<IList<Object>>
, в котором хранятся данные, извлеченные из таблиц Google api v4, и я пытаюсь заполнить эти данные в виде таблицы данных.Я могу вручную вставить эти данные в представление, но при зацикливании представление всегда заканчивается пустым.
public static IList<IList<Object>> Get(UserCredential credential, string spreadsheetId, string range)
{
var service = new SheetsService(new BaseClientService.Initializer()
{ HttpClientInitializer = credential, ApplicationName = ApplicationName, });
SpreadsheetsResource.ValuesResource.GetRequest request = service.Spreadsheets.Values.Get(spreadsheetId, range);
ValueRange response = request.Execute();
return response.Values;
}
private void populate_Table(object sender, RoutedEventArgs e)
{ // This function on_click populates the datagrid named JumpTable
this.JumpTable.ItemsSource = null; // Clears the current datagrid before getting new data
// Pulls in the 2d table from the client sheet
IList<IList<Object>> client_sheet = Get(SetCredentials(), "$spreadsheetIdPlaceholder", "Client!A2:H");
// Dictionary to set the properties that will be populated in the datagrid
Dictionary<string, object> entries = new Dictionary<string, object>();
/** [Status] [Non Functional]
for (int i = 0; i < 5; i++) // Using 5 as the count for testing
{
entries.Add("Tracker", new[] { new { // DataGrid To Add To
A = string.Format("{0}", client_sheet[i][0]), // Column [A] To Populate
B = string.Format("{0}", client_sheet[i][1]),
C = string.Format("{0}", client_sheet[i][2]),
D = string.Format("{0}", client_sheet[i][3])
} });
}
**/
/** [Status] [Functional]
entries.Add("Tracker", new[] { new { // DataGrid To Add To
A = string.Format("{0}", client_sheet[0][0]), // Column [A] To Populate
B = string.Format("{0}", client_sheet[0][1]),
C = string.Format("{0}", client_sheet[0][2]),
D = string.Format("{0}", client_sheet[0][3])
} });
**/
this.JumpTable.DataContext = entries; // Binds the entries to the datagrid
/** Alternative binding solution
* this.JumpTable.ItemsSource = entries;
**/
}
<DataGrid Grid.Row="3"
ItemsSource="{Binding [Tracker]}"
ScrollViewer.CanContentScroll="True"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
Name="JumpTable"
CanUserSortColumns="True"
CanUserAddRows="False"
AutoGenerateColumns="False"
materialDesign:DataGridAssist.CellPadding="13 8 8 8"
materialDesign:DataGridAssist.ColumnHeaderPadding="8"
Margin="0,10,0,0" >
<DataGrid.Columns>
<DataGridTextColumn Header="Tracker ID" IsReadOnly="True" Binding="{Binding A}" Width="275"/>
<DataGridTextColumn Header="Request ID" IsReadOnly="True" Binding="{Binding B}" Width="80"/>
<DataGridTextColumn Header="Req Requested Date" IsReadOnly="True" Binding="{Binding C}" Width="100"/>
<DataGridTextColumn Header="Requested Start Date" IsReadOnly="True" Binding="{Binding D}" Width="100"/>
</DataGrid.Columns>
</DataGrid>