Beispiel #1
0
        public void FormatCellWithColumnStateDefinition_WithArguments_FormatsCell(
            bool isReadOnly, string errorText, CellStyle cellStyle)
        {
            // Setup
            var definition = new DataGridViewColumnStateDefinition
            {
                ReadOnly  = isReadOnly,
                ErrorText = errorText,
                Style     = cellStyle
            };

            var mocks = new MockRepository();
            var row   = mocks.Stub <IHasColumnStateDefinitions>();

            row.Stub(r => r.ColumnStateDefinitions).Return(new Dictionary <int, DataGridViewColumnStateDefinition>
            {
                {
                    0, definition
                }
            });
            mocks.ReplayAll();

            using (var form = new Form())
                using (var dataGridViewControl = new DataGridViewControl())
                {
                    form.Controls.Add(dataGridViewControl);
                    form.Show();

                    dataGridViewControl.AddTextBoxColumn(null, "Test");
                    dataGridViewControl.SetDataSource(new[]
                    {
                        row
                    });

                    // Call
                    dataGridViewControl.FormatCellWithColumnStateDefinition(0, 0);

                    // Assert
                    DataGridViewCell cell = dataGridViewControl.Rows[0].Cells[0];
                    Assert.AreEqual(isReadOnly, cell.ReadOnly);
                    Assert.AreEqual(errorText, cell.ErrorText);
                    Assert.AreEqual(cellStyle.BackgroundColor, cell.Style.BackColor);
                    Assert.AreEqual(cellStyle.TextColor, cell.Style.ForeColor);

                    mocks.VerifyAll();
                }
        }
Beispiel #2
0
        public void FormatCellWithColumnStateDefinition_RowWithoutColumnStateDefinitions_DoesNotThrow()
        {
            // Setup
            using (var form = new Form())
                using (var dataGridViewControl = new DataGridViewControl())
                {
                    form.Controls.Add(dataGridViewControl);
                    form.Show();

                    dataGridViewControl.AddTextBoxColumn(null, "Test");
                    dataGridViewControl.SetDataSource(new[]
                    {
                        new object()
                    });

                    // Call
                    void Call() => dataGridViewControl.FormatCellWithColumnStateDefinition(0, 0);

                    // Assert
                    Assert.DoesNotThrow(Call);
                }
        }
Beispiel #3
0
 private void HandleCellStyling(object sender, DataGridViewCellFormattingEventArgs e)
 {
     DataGridViewControl.FormatCellWithColumnStateDefinition(e.RowIndex, e.ColumnIndex);
 }