public virtual void UpdateListRowsData(List <List <object> > viewData) { var feedDataType = LiveFeedData.GetType(); var gridRows = pnlDetail.Controls .OfType <ListRow>() .Where(l => l.Index >= 0) .OrderBy(l => l.Index) .ToList(); if (gridRows.Count == 0) { return; } for (int i = 0; i < gridRows.Count(); i++) { ListRow row = gridRows.FirstOrDefault(r => r.Index == i); if (i < viewData.Count) { List <object> dataRow = viewData[i]; for (int x = 0; x < dataRow.Count; x++) { var label = row .Controls .OfType <Label>() .FirstOrDefault(r => ((ViewListColumn)r.Tag).Index == x); var column = ((ViewListColumn)label.Tag); if (!String.IsNullOrEmpty(column.Format)) { label.Text = FormatValue(dataRow[x], column.Format); } else { label.Text = dataRow[x].ToString(); } } } else { // More grid rows than data rows row.ClearColumns(); } } }
public virtual List <List <object> > GetViewData() { string dataColumnErrorMessage = "No Data Member Defined"; var viewData = new List <List <object> >(); if (State.ListSettings.Columns.Count == 0) { return(viewData); } if (State.ListSettings.Columns.Any(c => String.IsNullOrEmpty(c.DataMember))) { return(viewData); } object[,] dataValues = new object[GridRows.Count, State.ListSettings.Columns.Count]; Type rootObjectType = null; object rootObjectValue = null; for (int i = 0; i < State.ListSettings.Columns.Count; i++) { var column = State.ListSettings.Columns.FirstOrDefault(c => c.Index == i); if (!String.IsNullOrEmpty(column.DataMember)) { var dataFullPath = column.DataFullPath; var dataPathSections = dataFullPath.Split('\\'); if (rootObjectType == null || rootObjectType.FullName != column.DataFeedFullName) { if (column.DataFeed == "LiveFeedData") { rootObjectType = LiveFeedData.GetType(); rootObjectValue = LiveFeedData; } else if (column.DataFeed == "LiveFlagData") { rootObjectType = LiveFlagData.GetType(); rootObjectValue = LiveFlagData; } else if (column.DataFeed == "LivePitData") { rootObjectType = LivePitData.GetType(); rootObjectValue = LivePitData; } else if (column.DataFeed == "LivePointsData") { rootObjectType = LivePointsData.GetType(); rootObjectValue = LivePointsData; } else if (column.DataFeed == "LiveQualifyingData") { rootObjectType = LiveQualifyingData.GetType(); rootObjectValue = LiveQualifyingData; } } string listPropertyName = String.Empty; string lengthPropertyName = String.Empty; object listValue = null; string[] dataPathSectionsFromList = null; Type sectionType = null; object sectionObject = null; if (rootObjectType.Name == "List`1") { listValue = rootObjectValue; lengthPropertyName = "Count"; } else if (rootObjectType.IsArray) { listValue = rootObjectValue; lengthPropertyName = "Length"; } else { PropertyInfo listPropertyInfo = null; lengthPropertyName = "Count"; sectionType = rootObjectType; sectionObject = rootObjectValue; int listSectionIndex = -1; for (int a = 0; a < dataPathSections.Length; a++) { if (dataPathSections[a].Contains("[]")) { listSectionIndex = a; listPropertyName = dataPathSections[a].Replace("[]", ""); listPropertyInfo = sectionType.GetProperty(listPropertyName); listValue = listPropertyInfo.GetValue(sectionObject); break; } } int sectionsFromListCount = dataPathSections.Length - listSectionIndex - 1; dataPathSectionsFromList = new string[sectionsFromListCount]; Array.Copy(dataPathSections, listSectionIndex + 1, dataPathSectionsFromList, 0, sectionsFromListCount); } int maxRows; if (listValue != null) { String indexerName = ((DefaultMemberAttribute)listValue.GetType() .GetCustomAttributes(typeof(DefaultMemberAttribute), true)[0]).MemberName; PropertyInfo indexerPropertyInfo = listValue.GetType().GetProperty(indexerName); PropertyInfo lengthPropertyInfo = listValue.GetType().GetProperty(lengthPropertyName); int listItemCount = (int)lengthPropertyInfo.GetValue(listValue); maxRows = State.ListSettings.MaxRows.HasValue ? State.ListSettings.MaxRows.Value <= listItemCount ? State.ListSettings.MaxRows.Value : listItemCount : listItemCount; maxRows = maxRows > GridRows.Count ? GridRows.Count : maxRows; for (int r = 0; r < maxRows; r++) { Object listItemValue = indexerPropertyInfo.GetValue(listValue, new Object[] { r }); PropertyInfo sectionProperty = null; object sectionValue = null; sectionObject = listItemValue; sectionType = sectionObject.GetType(); for (int x = 0; x < dataPathSectionsFromList.Length; x++) { sectionProperty = sectionType.GetProperty(dataPathSectionsFromList[x]); sectionValue = sectionProperty.GetValue(sectionObject); sectionType = sectionValue.GetType(); sectionObject = sectionValue; } dataValues[r, i] = sectionValue; } } else { // Property on the root object (ex LiveFeedData.LapNumber) // All rows get the same value. maxRows = State.ListSettings.MaxRows.HasValue ? State.ListSettings.MaxRows.Value : GridRows.Count; maxRows = maxRows > GridRows.Count ? GridRows.Count : maxRows; PropertyInfo sectionProperty = sectionType.GetProperty(dataPathSectionsFromList[0]); object sectionValue = sectionProperty.GetValue(sectionObject); for (int r = 0; r < maxRows; r++) { dataValues[r, i] = sectionValue; } } } else { var maxRows = State.ListSettings.MaxRows.HasValue ? State.ListSettings.MaxRows.Value <= GridRows.Count ? State.ListSettings.MaxRows.Value : GridRows.Count : GridRows.Count; for (int r = 0; r < maxRows; r++) { dataValues[r, i] = dataColumnErrorMessage; } } } var sortColumn = State.ListSettings.OrderedColumns.FirstOrDefault(c => c.SortType != Models.SortType.None); object[,] sortedDataRows = sortColumn == null ? dataValues : sortColumn.SortType == Models.SortType.Ascending ? dataValues.OrderBy(x => x[sortColumn.Index]) : dataValues.OrderByDescending(x => x[sortColumn.Index]); for (int g = 0; g < sortedDataRows.GetLength(0); g++) { List <object> viewRowData = new List <object>(); for (int h = 0; h < sortedDataRows.GetLength(1); h++) { viewRowData.Add(sortedDataRows[g, h]); } viewData.Add(viewRowData); } return(viewData); }