Back to Devexpress

SpreadsheetControl.RowHeightChanged Event

windowsforms-devexpress-dot-xtraspreadsheet-dot-spreadsheetcontrol-72bc10b1.md

latest5.7 KB
Original Source

SpreadsheetControl.RowHeightChanged Event

Occurs after the row height was changed.

Namespace : DevExpress.XtraSpreadsheet

Assembly : DevExpress.XtraSpreadsheet.v25.2.dll

NuGet Package : DevExpress.Win.Spreadsheet

Declaration

csharp
public event RowHeightChangedEventHandler RowHeightChanged
vb
Public Event RowHeightChanged As RowHeightChangedEventHandler

Event Data

The RowHeightChanged event's data class is RowHeightChangedEventArgs. The following properties provide information specific to this event:

PropertyDescription
IndexReturns the index of the row whose height was changed.

Remarks

The RowHeightChanged event occurs in the following cases:

See how to specify the row height or column width.

The example below shows how to use the SpreadsheetControl.RowHeightChanged and SpreadsheetControl.ColumnWidthChanged events to keep a picture in the center of the destination cell when a user changes the cell’s width or height.

csharp
public Form1()
{
    InitializeComponent();
    IWorkbook workbook = spreadsheetControl1.Document;
    Worksheet worksheet = workbook.Worksheets.ActiveWorksheet;

    // Add a picture to cell B2.
    Cell destCell = worksheet.Cells["B2"];
    Picture picture = worksheet.Pictures.AddPicture("DxLogo.png", destCell);
    // Specify the cell width and height.
    double cellWidth = destCell.ColumnWidth = picture.Width + 150;
    double cellHeight = destCell.RowHeight = picture.Height + 50;

    // Center the picture in the cell.
    double columnOffset = (destCell.ColumnWidth - picture.Width) / 2;
    double rowOffset = (destCell.RowHeight - picture.Height) / 2;
    picture.Move((float)rowOffset, (float)columnOffset);

    spreadsheetControl1.ColumnWidthChanged += (s, e) =>
    {
        if (e.Index == destCell.ColumnIndex)
        {
            // Move the picture to keep it in the center of the cell.
            columnOffset = (destCell.ColumnWidth - cellWidth) / 2;
            picture.Left += (float)columnOffset;
            cellWidth = destCell.ColumnWidth;
        }
    };

    spreadsheetControl1.RowHeightChanged += (s, e) =>
    {
        if (e.Index == destCell.RowIndex)
        {
            // Move the picture to keep it in the center of the cell.
            rowOffset = (destCell.RowHeight - cellHeight) / 2;
            picture.Top += (float)rowOffset;
            cellHeight = destCell.RowHeight;
        }
    };
}
vb
Public Class Form1
  Public Sub New()
      InitializeComponent()
      Dim workbook As IWorkbook = spreadsheetControl1.Document
      Dim worksheet As Worksheet = workbook.Worksheets.ActiveWorksheet

      ' Add a picture to cell B2.
      Dim destCell As Cell = worksheet.Cells("B2")
      Dim picture As Picture = worksheet.Pictures.AddPicture("DxLogo.png", destCell)
      ' Specify the cell width and height.
      destCell.ColumnWidth = picture.Width + 150
      Dim cellWidth As Double = destCell.ColumnWidth
      destCell.RowHeight = picture.Height + 50
      Dim cellHeight As Double = destCell.RowHeight

      ' Center the picture in the cell.
      Dim columnOffset As Double = (destCell.ColumnWidth - picture.Width) / 2
      Dim rowOffset As Double = (destCell.RowHeight - picture.Height) / 2
      picture.Move(CSng(rowOffset), CSng(columnOffset))

      AddHandler SpreadsheetControl1.ColumnWidthChanged,
          Sub(s, e)
              If e.Index = destCell.ColumnIndex Then
                  ' Move the picture to keep it in the center of the cell.
                  columnOffset = (destCell.ColumnWidth - cellWidth) / 2
                  picture.Left += CSng(columnOffset)
                  cellWidth = destCell.ColumnWidth
              End If
          End Sub

      AddHandler SpreadsheetControl1.RowHeightChanged,
          Sub(s, e)
              If e.Index = destCell.RowIndex Then
                  ' Move the picture to keep it in the center of the cell.
                  rowOffset = (destCell.RowHeight - cellHeight) / 2
                  picture.Top += CSng(rowOffset)
                  cellHeight = destCell.RowHeight
              End If
            End Sub
  End Sub
End Class

See Also

ColumnWidthChanged

How to: Specify Row Height or Column Width

SpreadsheetControl Class

SpreadsheetControl Members

DevExpress.XtraSpreadsheet Namespace