/// <summary> /// DataGridViewのカラム幅を前回保存したファイルから読込 /// </summary> /// <remarks>DataGridViewのカラム幅をXML形式でデシリアライズ</remarks> public void ReadColWidths() { try { // EXEファイルのPATH String ExePath = System.AppDomain.CurrentDomain.BaseDirectory; // XMLファイルのPATH String XmlPath = ExePath + "\\" + this.Parent.Name + "_" + this.Name + ".xml"; // XMLファイルオープン StreamReader sr = new StreamReader(XmlPath, Encoding.Default); try { // シリアライザー XmlSerializer serializer = new XmlSerializer(typeof(ColWidths)); // XMLファイル読込 ColWidths colw = new ColWidths(); colw = (ColWidths)(serializer.Deserialize(sr)); // DataGridViewにカラム幅設定 for (int i = 0; i <= this.Columns.Count - 1; i++) { this.Columns[i].Width = colw.Widths[i]; } } catch { } finally { if (sr != null) { sr.Close(); } } } catch { } }
public CustomGridModel() { // Initial dimension RowCount = 1000; ColCount = 13; // initial row and column sizes Rows.DefaultSize = 18; Cols.DefaultSize = 70; Properties.GridLineColor = System.Drawing.Color.FromArgb(208, 215, 229); RowHeights[0] = 21; ColWidths[0] = 35; RowHeights.ResetModified(); ColWidths.ResetModified(); // fixed columns Cols.HeaderCount = 1; Cols.FrozenCount = 2; // standard base styles BaseStylesMap.RegisterStandardStyles(); GridStyleInfo standardStyle = BaseStylesMap["Standard"].StyleInfo; standardStyle.MergeCell = GridMergeCellDirection.RowsInColumn; GridStyleInfo rowHeaderStyle = BaseStylesMap["Row Header"].StyleInfo; //rowHeaderStyle.CellType = "Static"; rowHeaderStyle.MergeCell = GridMergeCellDirection.RowsInColumn; BaseStylesMap.Modified = false; CellModels.Add("CustomCell", new CustomCellModel(this)); // Other options Options.MergeCellsMode = GridMergeCellsMode.OnDemandCalculation | GridMergeCellsMode.MergeRowsInColumn; Options.SmoothControlResize = false; // At the momemnt the Excel-like selection feature is broken when using merge cells. Options.ExcelLikeCurrentCell = false; Options.ExcelLikeSelectionFrame = false; Options.GridVisualStyles = GridVisualStyles.Office2007Blue; Options.DefaultGridBorderStyle = GridBorderStyle.Solid; }
public PerformanceGridModel() { CommandStack.Enabled = false; Rows.DefaultSize = 17; Cols.DefaultSize = 65; RowHeights[0] = 21; ColWidths[0] = 35; RowHeights.ResetModified(); ColWidths.ResetModified(); Options.ExcelLikeCurrentCell = false; Options.ExcelLikeSelectionFrame = false; Options.AllowDragSelectedCols = false; Options.AllowDragSelectedRows = false; CommandStack.Enabled = false; Options.FloatCellsMode = GridFloatCellsMode.None; BaseStylesMap.RegisterStandardStyles(); }
/// <summary> /// DataGridViewのカラム幅をファイルへ保存 /// </summary> /// <remarks>DataGridViewのカラム幅をXML形式でシリアライズ</remarks> public void SaveColWidths() { try { // EXEファイルのPATH String ExePath = System.AppDomain.CurrentDomain.BaseDirectory; // XMLファイルのPATH String XmlPath = ExePath + "\\" + this.Parent.Name + "_" + this.Name + ".xml"; // XMLファイルオープン StreamWriter sw = new StreamWriter(XmlPath, false, Encoding.Default); try { // シリアライザー XmlSerializer serializer = new XmlSerializer(typeof(ColWidths)); // DataGridViewのカラム幅取得 ColWidths colw = new ColWidths(); Array.Resize <int>(ref colw.Widths, this.Columns.Count); for (int i = 0; i <= this.Columns.Count - 1; i++) { colw.Widths[i] = this.Columns[i].Width; } // XMLファイル保存 serializer.Serialize(sw, colw); } catch { } finally { // XMLファイルクローズ if (sw != null) { sw.Close(); } } } catch { } }