/// <summary></summary> private void FillGridOld() { gridOld.BeginUpdate(); gridOld.ListGridColumns.Clear(); gridOld.ListGridRows.Clear(); if (gridMain.GetSelectedIndex() < 0) { gridOld.EndUpdate(); return; } if (string.IsNullOrEmpty(gridMain.SelectedTag <WikiListHist>()?.ListHeaders)) { gridMain.SelectedGridRows[0].Tag = WikiListHists.SelectOne(gridMain.SelectedTag <WikiListHist>()?.WikiListHistNum ?? 0); } Dictionary <string, int> dictColWidths = WikiListHeaderWidths.GetFromListHist(gridMain.SelectedTag <WikiListHist>()) .ToDictionary(x => x.ColName, x => x.ColWidth); using (DataTable table = new DataTable()) { using (StringReader sr = new StringReader(gridMain.SelectedTag <WikiListHist>().ListContent)) using (XmlReader xmlReader = XmlReader.Create(sr)) { try { table.ReadXml(xmlReader); } catch (Exception) { MsgBox.Show(this, "Corruption detected in the Old Revision table. Partial data will be displayed. Please call us for support."); gridOld.EndUpdate(); return; } } gridOld.ListGridColumns.AddRange( table.Columns.OfType <DataColumn>().Select(x => new GridColumn(x.ColumnName, dictColWidths.TryGetValue(x.ColumnName, out int width)?width:100))); gridOld.ListGridRows.AddRange(table.Select().Select(x => new GridRow(x.ItemArray.Select(y => y.ToString()).ToArray()))); } gridOld.EndUpdate(); }
/// <summary></summary> private void FillGridOld() { List <WikiListHeaderWidth> colHeaderWidths = new List <WikiListHeaderWidth>(); _tableOld = new DataTable(); if (gridMain.GetSelectedIndex() > -1) { colHeaderWidths = WikiListHeaderWidths.GetFromListHist(_listWikiListHists[gridMain.GetSelectedIndex()]); using (XmlReader xmlReader = XmlReader.Create(new StringReader(_listWikiListHists[gridMain.GetSelectedIndex()].ListContent))) { try { _tableOld.ReadXml(xmlReader); } catch (Exception) { MsgBox.Show(this, "Corruption detected in the Old Revision table. Partial data will be displayed. Please call us for support."); } } } gridOld.BeginUpdate(); gridOld.Columns.Clear(); ODGridColumn col; for (int c = 0; c < _tableOld.Columns.Count; c++) { int colWidth = 100; //100 = default value in case something is malformed in the database. foreach (WikiListHeaderWidth colHead in colHeaderWidths) { if (colHead.ColName == _tableOld.Columns[c].ColumnName) { colWidth = colHead.ColWidth; break; } } col = new ODGridColumn(_tableOld.Columns[c].ColumnName, colWidth, false); gridOld.Columns.Add(col); } gridOld.Rows.Clear(); ODGridRow row; for (int i = 0; i < _tableOld.Rows.Count; i++) { row = new ODGridRow(); for (int c = 0; c < _tableOld.Columns.Count; c++) { row.Cells.Add(_tableOld.Rows[i][c].ToString()); } gridOld.Rows.Add(row); gridOld.Rows[i].Tag = i; } gridOld.EndUpdate(); }