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


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

 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或将消息附加到多行TextBoxTo 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名为DataGridView1To 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.AppendFormat("{0} = {1}", "MinimumHeight", e.MinimumHeight );
messageBoxCS.AppendFormat("{0} = {1}", "RowIndex", e.RowIndex );
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.AppendFormat("{0} = {1}", "MinimumHeight", e.MinimumHeight)
    messageBoxVB.AppendFormat("{0} = {1}", "RowIndex", e.RowIndex)
    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属性是trueThis 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.