DataGridView.RowHeightInfoNeeded DataGridView.RowHeightInfoNeeded DataGridView.RowHeightInfoNeeded DataGridView.RowHeightInfoNeeded Event

定义

请求有关行高度的信息时发生。Occurs when information about row height is requested.

public:
 event System::Windows::Forms::DataGridViewRowHeightInfoNeededEventHandler ^ RowHeightInfoNeeded;
public event System.Windows.Forms.DataGridViewRowHeightInfoNeededEventHandler RowHeightInfoNeeded;
member this.RowHeightInfoNeeded : System.Windows.Forms.DataGridViewRowHeightInfoNeededEventHandler 
Public Custom Event RowHeightInfoNeeded As DataGridViewRowHeightInfoNeededEventHandler 

示例

下面的代码示例演示如何使用此成员。The following code example demonstrates the use of this member. 在此示例中, 事件处理程序报告RowHeightInfoNeeded事件的发生。In the example, an event handler reports on the occurrence of the RowHeightInfoNeeded event. 此报表可帮助你了解何时发生事件, 并可帮助你进行调试。This report helps you to learn when the event occurs and can assist you in debugging. 若要报告多个事件或频繁发生的事件, 请考虑MessageBox.ShowConsole.WriteLine消息替换为多行或将TextBox其追加到多行。To report on multiple events or on events that occur frequently, consider replacing MessageBox.Show with Console.WriteLine or appending the message to a multiline TextBox.

若要运行示例代码, 请将其粘贴到包含名为DataGridView DataGridView1的类型的实例的项目中。To run the example code, paste it into a project that contains an instance of type DataGridView named DataGridView1. 然后, 确保事件处理程序与RowHeightInfoNeeded事件相关联。Then ensure that the event handler is associated with the RowHeightInfoNeeded event.

private void DataGridView1_RowHeightInfoNeeded(Object sender, DataGridViewRowHeightInfoNeededEventArgs e) {

System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "Height", e.Height );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "MinimumHeight", e.MinimumHeight );
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "RowIndex", e.RowIndex );
messageBoxCS.AppendLine();
MessageBox.Show(messageBoxCS.ToString(), "RowHeightInfoNeeded Event" );
}
Private Sub DataGridView1_RowHeightInfoNeeded(sender as Object, e as DataGridViewRowHeightInfoNeededEventArgs) _ 
     Handles DataGridView1.RowHeightInfoNeeded

    Dim messageBoxVB as New System.Text.StringBuilder()
    messageBoxVB.AppendFormat("{0} = {1}", "Height", e.Height)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "MinimumHeight", e.MinimumHeight)
    messageBoxVB.AppendLine()
    messageBoxVB.AppendFormat("{0} = {1}", "RowIndex", e.RowIndex)
    messageBoxVB.AppendLine()
    MessageBox.Show(messageBoxVB.ToString(),"RowHeightInfoNeeded Event")

End Sub

注解

此事件可用于在执行排序操作后保留自定义行高度。This event is useful for preserving custom row heights after a sorting operation. 这是必需的, 因为排序操作通常由数据源进行处理, 而数据源并不跟踪数据行和控件中各行之间的对应关系。This is necessary because sorting operations are normally handled by the data source, which does not keep track of the correspondence between rows of data and rows in the control. 仅当DataSource设置了属性或VirtualMode属性为true时, 才会发生此事件。This event occurs only when the DataSource property has been set or when the VirtualMode property is true. 在后一种情况下, 你将提供自己的数据存储和排序操作。In the latter case, you provide your own data store and sorting operations. RowHeightInfoPushed处理事件, 以便在用户更改行高时存储更新的高度信息。Handle the RowHeightInfoPushed event to store updated height information when the user changes a row height. RowHeightInfoNeeded控件需要时, 使用检索存储的高度信息。Use RowHeightInfoNeeded to retrieve the stored height information when the control needs it.

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

适用于

另请参阅