DataGridView.AutoSizeRowsModeChanged DataGridView.AutoSizeRowsModeChanged DataGridView.AutoSizeRowsModeChanged DataGridView.AutoSizeRowsModeChanged Event

定义

DataGridViewAutoSizeRowsMode 属性的值更改时发生。Occurs when the value of the DataGridViewAutoSizeRowsMode property changes.

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 

示例

下面的代码示例演示如何使用此事件。The following code example illustrates the use of this event. 此示例摘自一个更大的示例中提供如何:自动调整单元格的内容何时更改在 Windows 窗体 DataGridView 控件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

注解

有关如何处理事件的详细信息,请参阅处理和引发事件For more information about how to handle events, see Handling and Raising Events.

适用于

另请参阅