Vermilliest

Untitled

Nov 12th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.58 KB | None | 0 0
  1.             dataGridView.Columns.Clear( );
  2.             dataGridView.ColumnCount = (int)matrix.Width;
  3.             float rowsHeight = (float)dataGridView.Height / matrix.Height;
  4.             float cellsWidth = (float)dataGridView.Width / matrix.Width;
  5.             for (uint rowIndex = 0u; rowIndex < matrix.Height; rowIndex++) {
  6.                 DataGridViewRow row = new DataGridViewRow( );
  7.                 row.CreateCells(dataGridView, matrix.Width);
  8.                 for (uint columnIndex = 0u; columnIndex < matrix.Width; columnIndex++) {
  9.                     bool value = matrix[columnIndex, rowIndex];
  10.                     var cell = row.Cells[(int)columnIndex];
  11.                     cell.Value = value ? 1 : 0;
  12.                     cell.Style.BackColor = //columnIndex >= k ? Color.FromArgb(192, 192, 192) :
  13.                         value ? Color.FromArgb(60, 192, 60) : Color.FromArgb(192, 60, 60);
  14.                     cell.Style.ForeColor = Color.Black;
  15.                     cell.Style.Font = new Font("Consolas", 9);
  16.                 }
  17.                 dataGridView.Rows.Add(row);
  18.                 row.Height = (int)(rowIndex * rowsHeight) - (int)(((int)rowIndex - 1) * rowsHeight);
  19.             }
  20.             for (int columnIndex = 0; columnIndex < dataGridView.ColumnCount; columnIndex++) {
  21.                 var column = dataGridView.Columns[columnIndex];
  22.                 column.SortMode = DataGridViewColumnSortMode.NotSortable;
  23.                 column.Width = (int)(columnIndex * cellsWidth) - (int)((columnIndex - 1) * cellsWidth);
  24.             }
  25.             dataGridView.ClearSelection( );
Advertisement
Add Comment
Please, Sign In to add comment