DataGridViewAutoSizeModeEventArgs.PreviousModeAutoSized Property

Definition

Gets a value specifying whether the DataGridView was previously set to automatically resize.

public:
 property bool PreviousModeAutoSized { bool get(); };
public bool PreviousModeAutoSized { get; }
member this.PreviousModeAutoSized : bool
Public ReadOnly Property PreviousModeAutoSized As Boolean

Property Value

true if the AutoSizeRowsMode property was previously set to any DataGridViewAutoSizeRowsMode value other than None or the RowHeadersWidthSizeMode property was previously set to any DataGridViewRowHeadersWidthSizeMode value other than DisableResizing or EnableResizing; otherwise, false.

Examples

The following code example uses the PreviousModeAutoSized property to check the previous AutoSizeRowsMode value for a DataGridView. This code example is part of a larger example provided at How to: Automatically Resize Cells When Content Changes in the Windows Forms DataGridView Control.

void WatchRowsModeChanges( Object^ /*sender*/, DataGridViewAutoSizeModeEventArgs^ modeEvent )
{
   Label^ label = dynamic_cast<Label^>(flowLayoutPanel1->Controls[ currentLayoutName ]);
   if ( modeEvent->PreviousModeAutoSized )
   {
      label->Text = String::Format( "changed to a different {0}{1}", label->Name, dataGridView1->AutoSizeRowsMode );
   }
   else
   {
      label->Text = String::Concat( label->Name, dataGridView1->AutoSizeRowsMode );
   }
}
private void WatchRowsModeChanges(object sender,
    DataGridViewAutoSizeModeEventArgs modeEvent)
{
    Label label =
        (Label)flowLayoutPanel1.Controls[currentLayoutName];

    if (modeEvent.PreviousModeAutoSized)
    {
        label.Text = "changed to a different " +
            label.Name +
            dataGridView1.AutoSizeRowsMode.ToString();
    }
    else
    {
        label.Text = label.Name +
            dataGridView1.AutoSizeRowsMode.ToString();
    }
}
Private Sub WatchRowsModeChanges(ByVal sender As Object, _
    ByVal modeEvent As DataGridViewAutoSizeModeEventArgs) _
    Handles DataGridView1.AutoSizeRowsModeChanged

    Dim label As Label = CType(FlowLayoutPanel1.Controls _
        (currentLayoutName), Label)

    If modeEvent.PreviousModeAutoSized Then
        label.Text = "changed to different " & label.Name & _
            DataGridView1.AutoSizeRowsMode.ToString()
    Else
        label.Text = label.Name & _
            DataGridView1.AutoSizeRowsMode.ToString()
    End If
End Sub

Remarks

The DataGridViewAutoSizeModeEventArgs class is used with the DataGridView.AutoSizeRowsModeChanged and DataGridView.RowHeadersWidthSizeModeChanged events, so this property relates specifically to the previous state of either the DataGridView.AutoSizeRowsMode or DataGridView.RowHeadersWidthSizeMode property

Applies to

See also