// Set the row's height without overwriting the explicit_height, so we // can go back to the user's requested height when they turn off AutoSize internal void SetAutoSizeHeight(int height) { this.height = height; if (DataGridView != null) { DataGridView.Invalidate(); DataGridView.OnRowHeightChanged(new DataGridViewRowEventArgs(this)); } }
internal override void Initialize(List <GPXLoader.Cache> allgc, System.Windows.Forms.DataGridView grid) { grid.ColumnCount = 9; grid.SelectionMode = DataGridViewSelectionMode.CellSelect; for (int d = 0; d < 9; d++) { var row = new DataGridViewRow(); string diff = ((d + 2) * 0.5).ToString(); row.HeaderCell.Value = diff; for (int t = 0; t < 9; t++) { string terr = ((t + 2) * 0.5).ToString(); //initialization for columns if (d == 0) { var col = grid.Columns[t]; col.Name = terr; col.DataPropertyName = "count"; col.SortMode = DataGridViewColumnSortMode.NotSortable; col.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; col.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter; } var thisDT = allgc.Where(g => g.Difficulty == diff && g.Terrain == terr); //Debug.Write(string.Format("{0}/{1}", diff, terr)); //Debug.Write(string.Format("{0} ", thisDT.Count())); row.Cells.Add(new DataGridViewTextBoxCell() { Value = thisDT.Count(), Tag = thisDT.ToList() }); } grid.Rows.Add(row); grid.Invalidate(); } }
void ApplyDataGridViewPrefs(DataGridView dataGridView, Preferences prefs) { if (dataGridView.Columns.Count > 1) { if (prefs.setLastColumnWidth) { dataGridView.Columns[dataGridView.Columns.Count - 1].MinimumWidth = prefs.lastColumnWidth; } else { // Workaround for a .NET bug which brings the DataGridView into an unstable state (causing lots of NullReferenceExceptions). dataGridView.FirstDisplayedScrollingColumnIndex = 0; dataGridView.Columns[dataGridView.Columns.Count - 1].MinimumWidth = 5; // default } } if (dataGridView.RowCount > 0) { dataGridView.UpdateRowHeightInfo(0, true); } dataGridView.Invalidate(); dataGridView.Refresh(); AutoResizeColumns(dataGridView); }
private static void UpDownOrDelete(bool? isUp, DataGridView dataGridView1) { Clips.BoardDataTable clips = null; if (dataGridView1 == null || dataGridView1.SelectedCells == null || dataGridView1.SelectedCells.Count < 1 || (clips = dataGridView1.DataSource as Clips.BoardDataTable) == null) return; dataGridView1.SuspendLayout(); Dictionary<int, int> idxs = new Dictionary<int, int>(); for (int i = 0; i < dataGridView1.SelectedCells.Count; i++) idxs.Add(dataGridView1.SelectedCells[i].RowIndex, -1); List<int> rows = new List<int>(); foreach (int id in idxs.Keys) rows.Add(id); for (int i = rows.Count - 1; i >= 0; i--) if (rows[i] < 0 || rows[i] >= dataGridView1.RowCount) return; rows.Sort(); if (isUp == null) { for (int i = rows.Count - 1; i >= 0; i--) clips.Rows.RemoveAt(rows[i]); } else { int diff = rows[rows.Count - 1] - rows[0]; int plus = 1; int temp = 0; for (int i = 1; i < rows.Count; i++) { if (Math.Abs(rows[i - 1] - rows[i]) == 1) { temp++; if (i != rows.Count - 1) continue; } if (plus < temp) plus = temp; temp = 0; } diff += plus; for (int i = 0; i < rows.Count; i++) idxs[rows[i]] = rows[i] + (isUp == true ? -diff : diff); for (int i = 0; i < rows.Count; i++) if (idxs[rows[i]] < 0 || idxs[rows[i]] >= dataGridView1.RowCount) return; List<Clips.BoardRow> boards = new List<Clips.BoardRow>(); for (int i = rows.Count - 1; i >= 0; i--) { Clips.BoardRow board = clips.NewBoardRow(); board.ItemArray = clips[rows[i]].ItemArray; boards.Add(board); clips.Rows.RemoveAt(rows[i]); } for (int i = 0; i < boards.Count; i++) clips.Rows.InsertAt(boards[boards.Count - i - 1], idxs[rows[i]]); for (int i = 0; i < dataGridView1.SelectedCells.Count; i++) dataGridView1.SelectedCells[i--].Selected = false; for (int i = 0; i < rows.Count; i++) dataGridView1[(int)GridColumns.BoardText, idxs[rows[i]]].Selected = true; } dataGridView1.Invalidate(); dataGridView1.ResumeLayout(); }
// ================================================================================= // Forcing a DataGridview display update // Ugly hack if you ask me, but MS didn't give us any other reliable way... private void Update_GridView(DataGridView Grid) { Grid.Invalidate(); Grid.Update(); }
private void ClearSelection(DataGridView dgv) { if (dgv.CurrentCell != null) { dgv.ClearSelection(); int index = dgv.CurrentRow.Index; dgv.CurrentCell = null; Rectangle rect = dgv.GetRowDisplayRectangle(index, false); rect.Inflate(1, 1); dgv.Invalidate(rect); } }