/// <summary> Create a row. Rows must be created via this call</summary> public GLDataGridViewRow CreateRow() { GLDataGridViewRow row = new GLDataGridViewRow(); row.Parent = this; row.DefaultCellStyle.Parent = defaultcellstyle; row.HeaderStyle.Parent = rowheaderstyle; row.Height = 24; return(row); }
/// <summary> remove a row at row </summary> public void RemoveRow(int row) { GLDataGridViewRow rw = rows[row]; rw.Parent = null; rw.DefaultCellStyle.Parent = null; rw.HeaderStyle.Parent = null; rw.HeaderStyle.Changed = null; rw.Changed = null; contentpanel.RemoveRow(row); rows.RemoveAt(row); for (int i = row; i < rows.Count; i++) { rows[i].SetRowNo(i, (i & 1) != 0 ? DefaultAltRowCellStyle : DefaultCellStyle); } UpdateScrollBar(); }
internal void PerformAutoSize(GLDataGridViewRow r) { if (r.AutoSizeGeneration != autosizegeneration) { // System.Diagnostics.Debug.WriteLine($"Perform autosize {r.Index}"); int maxh = 0; for (int i = 0; i < columns.Count; i++) // each column cell gets a chance to autosize against the col width { if (i < r.Cells.Count) { Size s = r.Cells[i].PerformAutoSize(Math.Max(columns[i].Width, columns[i].MinimumWidth)); // max of these just in case we have not performed layout maxh = Math.Max(maxh, s.Height); } } r.SetAutoSizeHeight(autosizegeneration, maxh); } }
/// <summary> Add a row. If insertatrow=-1, add to end. Else inserted before index</summary> public void AddRow(GLDataGridViewRow row, int insertatrow = -1) { System.Diagnostics.Debug.Assert(row.Parent == this && row.HeaderStyle.Parent != null); // ensure created by us row.HeaderStyle.Changed += (e1) => { ContentInvalidateLayout(); }; // header style changed, need a complete refresh row.AutoSizeGeneration = 0; row.Changed += (e1) => { contentpanel.RowChanged(row.Index); // inform CP UpdateScrollBar(); // update scroll bar }; row.SelectionChanged += (rw, cellno) => { //System.Diagnostics.Debug.WriteLine($"Selection changed on {rw.Index} {cellno}"); if (cellno == -1) // if whole row select { if (rw.Selected) // turning on { if (!AllowUserToSelectMultipleRows) // if not allowed multirow, clear all { ClearSelection(); } if (!selectedcells.ContainsKey(rw.Index)) { selectedcells[rw.Index] = new HashSet <int>(); } foreach (var c in rw.Cells) { selectedcells[rw.Index].Add(c.Index); } SelectedRow?.Invoke(rw, true); } else { // turning off foreach (var c in rw.Cells) { selectedcells[rw.Index].Remove(c.Index); } if (selectedcells[rw.Index].Count == 0) { selectedcells.Remove(rw.Index); } SelectedRow?.Invoke(rw, false); } } else if (rows[rw.Index].Cells[cellno].Selected) // individual cell turning on { if (!selectedcells.ContainsKey(rw.Index)) { selectedcells[rw.Index] = new HashSet <int>(); } selectedcells[rw.Index].Add(cellno); SelectedCell?.Invoke(rows[rw.Index].Cells[cellno], true); } else { selectedcells[rw.Index].Remove(cellno); // or turning off if (selectedcells[rw.Index].Count == 0) { selectedcells.Remove(rw.Index); } SelectedCell?.Invoke(rows[rw.Index].Cells[cellno], false); } contentpanel.RowChanged(row.Index); // inform CP }; if (insertatrow == -1) { row.SetRowNo(rows.Count, (rows.Count & 1) != 0 ? DefaultAltRowCellStyle : DefaultCellStyle); rows.Add(row); contentpanel.AddRow(row.Index); // see if content panel needs redrawing } else { rows.Insert(insertatrow, row); for (int i = insertatrow; i < rows.Count; i++) { rows[i].SetRowNo(i, (i & 1) != 0 ? DefaultAltRowCellStyle : DefaultCellStyle); } contentpanel.InsertRow(row.Index); // see if content panel needs redrawing } UpdateScrollBar(); }