Edytuj

Udostępnij za pośrednictwem


DataGridView.AutoSizeRowsModeChanged Event

Definition

Occurs when the value of the DataGridViewAutoSizeRowsMode property changes.

public:
 event System::Windows::Forms::DataGridViewAutoSizeModeEventHandler ^ AutoSizeRowsModeChanged;
public event System.Windows.Forms.DataGridViewAutoSizeModeEventHandler AutoSizeRowsModeChanged;
public event System.Windows.Forms.DataGridViewAutoSizeModeEventHandler? AutoSizeRowsModeChanged;
member this.AutoSizeRowsModeChanged : System.Windows.Forms.DataGridViewAutoSizeModeEventHandler 
Public Custom Event AutoSizeRowsModeChanged As DataGridViewAutoSizeModeEventHandler 

Event Type

Examples

The following code example illustrates the use of this event. This example is part of a larger example available in 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

For more information about how to handle events, see Handling and Raising Events.

Applies to

See also