/// <summary> /// Method to call from Event handler for Sheet-Category DataGridView CellValueNeeded event. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public static void SheetCategoryCellValueNeeded(object sender, DataGridViewCellValueEventArgs e, Sheet sheet, Category.SheetCategoryType sheetCategoryType) { DataGridView sheetCategory = (sender as DataGridView); List <Category> filterCategory = default(List <Category>); try { if (sheetCategoryType == Category.SheetCategoryType.Filter) { if (!_IsReshapingGrid) { //only works if header is displayed //category item name; category name is put in header when grid is re-configured. SelectedItemIndex must be valid. filterCategory = sheet.CategoryFilters(); e.Value = filterCategory[e.ColumnIndex].Items[filterCategory[e.ColumnIndex].SelectedItemIndex].Name; ////use if header is not displayed ////category name //e.Value = sheet.CategoryFilters()[e.ColumnIndex].Name; } else { e.Value = null; } } else if (sheetCategoryType == Category.SheetCategoryType.X) { if (!_IsReshapingGrid) { //category name e.Value = sheet.CategoryX()[e.RowIndex].Name; } else { e.Value = null; } } else if (sheetCategoryType == Category.SheetCategoryType.Y) { if (!_IsReshapingGrid) { //category name e.Value = sheet.CategoryY()[e.ColumnIndex].Name; } else { e.Value = null; } } } catch (Exception ex) { Log.Write(ex, MethodBase.GetCurrentMethod(), EventLogEntryType.Error); throw; } }
/// <summary> /// Clears grid and builds a new one. Adds rows and columns, and formats them. /// </summary> /// <param name="grid"></param> /// <param name="sheet"></param> /// <param name="sheetCategoryType"></param> private static void BuildSheetCategory(DataGridView grid, Sheet sheet, Category.SheetCategoryType sheetCategoryType) { Int32 columnCount = -1; Int32 rowCount = -1; try { ConfigureVirtualDataGridView(grid); // Add columns and rows to the DataGridView. grid.Rows.Clear(); grid.Columns.Clear(); if (sheet != null) { if (sheetCategoryType == Category.SheetCategoryType.Filter) { grid.ColumnHeadersVisible = true; columnCount = sheet.CategoryFilters().Count; rowCount = 1; ConfigureVirtualDataGridViewTextCells(grid, columnCount, rowCount, (i => sheet.CategoryFilters()[i].Name)); } else if (sheetCategoryType == Category.SheetCategoryType.X) { columnCount = 1; rowCount = sheet.CategoryX().Count; ConfigureVirtualDataGridViewTextCells(grid, columnCount, rowCount, (i => "")); } else if (sheetCategoryType == Category.SheetCategoryType.Y) { columnCount = sheet.CategoryY().Count; rowCount = 1; ConfigureVirtualDataGridViewTextCells(grid, columnCount, rowCount, (i => "")); } } } catch (Exception ex) { Log.Write(ex, MethodBase.GetCurrentMethod(), EventLogEntryType.Error); throw; } }