Share via


DataGrid.AllowNavigationChanged 事件

AllowNavigation 属性更改后发生。

**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)

语法

声明
Public Event AllowNavigationChanged As EventHandler
用法
Dim instance As DataGrid
Dim handler As EventHandler

AddHandler instance.AllowNavigationChanged, handler
public event EventHandler AllowNavigationChanged
public:
event EventHandler^ AllowNavigationChanged {
    void add (EventHandler^ value);
    void remove (EventHandler^ value);
}
/** @event */
public void add_AllowNavigationChanged (EventHandler value)

/** @event */
public void remove_AllowNavigationChanged (EventHandler value)
JScript 支持使用事件,但不支持进行新的声明。

备注

如果 AllowNavigation 属性设置为 false,则不显示指向子表的链接。

有关处理事件的更多信息,请参见 使用事件

示例

下面的代码示例重置 AllowNavigation 属性并引发 AllowNavigationChanged 事件。

' Create an instance of the 'AllowNavigationChanged' EventHandler.
Private Sub CallAllowNavigationChanged()
   AddHandler myDataGrid.AllowNavigationChanged, AddressOf Grid_AllowNavChange
End Sub 'CallAllowNavigationChanged


' Set the 'AllowNavigation' property on click of a button.
 Private Sub myButton_Click(ByVal sender As Object, ByVal e As EventArgs)
     If myDataGrid.AllowNavigation = True Then
         myDataGrid.AllowNavigation = False
     Else
         myDataGrid.AllowNavigation = True
     End If
 End Sub 'myButton_Click
 
' Raise the event when 'AllowNavigation' property is changed.
 Private Sub Grid_AllowNavChange(ByVal sender As Object, ByVal e As EventArgs)
     Dim myString As String = "AllowNavigationChanged event raised, Navigation "
     Dim myBool As Boolean = myDataGrid.AllowNavigation
     ' Create appropriate alert message.
     myString = myString + IIF(mybool, "is", "is not") + "allowed"
     ' Show information about navigation.
     MessageBox.Show(myString, "Navigation information")
 End Sub 'Grid_AllowNavChange
// Create an instance of the 'AllowNavigationChanged' EventHandler.
private void CallAllowNavigationChanged()
{
   myDataGrid.AllowNavigationChanged += 
                                   new EventHandler(Grid_AllowNavChange);
}

// Set the 'AllowNavigation' property on click of a button.
private void myButton_Click(object sender, EventArgs e)
{
   if (myDataGrid.AllowNavigation == true)
      myDataGrid.AllowNavigation = false;
   else
      myDataGrid.AllowNavigation = true;
}

// Raise the event when 'AllowNavigation' property is changed.
private void Grid_AllowNavChange(object sender, EventArgs e)
{
   string myString = "AllowNavigationChanged event raised, Navigation ";
   bool myBool = myDataGrid.AllowNavigation;
   // Create appropriate alert message.
   myString = myString + (myBool ? " is " : " is not ") + "allowed";
   // Show information about navigation.
   MessageBox.Show(myString, "Navigation information");
}
private:
   // Create an instance of the 'AllowNavigationChanged' EventHandler.
   void CallAllowNavigationChanged()
   {
      myDataGrid->AllowNavigationChanged += gcnew EventHandler( this, &MyDataGrid::Grid_AllowNavChange );
   }

   // Set the 'AllowNavigation' property on click of a button.
private:
   void myButton_Click( Object^ /*sender*/, EventArgs^ /*e*/ )
   {
      if ( myDataGrid->AllowNavigation == true )
            myDataGrid->AllowNavigation = false;
      else
            myDataGrid->AllowNavigation = true;
   }

   // Raise the event when 'AllowNavigation' property is changed.
private:
   void Grid_AllowNavChange( Object^ /*sender*/, EventArgs^ /*e*/ )
   {
      String^ myString = "AllowNavigationChanged event raised, Navigation ";
      bool myBool = myDataGrid->AllowNavigation;

      // Create appropriate alert message.
      myString = String::Concat( myString, myBool ? (String^)" is " : " is not ", "allowed" );

      // Show information about navigation.
      MessageBox::Show( myString, "Navigation information" );
   }
// Create an instance of the 'AllowNavigationChanged' EventHandler.
private void CallAllowNavigationChanged()
{
    myDataGrid.add_AllowNavigationChanged(new EventHandler(
        GridAllowNavChange));
} //CallAllowNavigationChanged

// Set the 'AllowNavigation' property on click of a button.
protected void myButton_Click(Object sender, EventArgs e)
{
    if (myDataGrid.get_AllowNavigation() == true) {
        myDataGrid.set_AllowNavigation(false);
    }
    else {
        myDataGrid.set_AllowNavigation(true);
    }
} //myButton_Click

// Raise the event when 'AllowNavigation' property is changed.
protected void GridAllowNavChange(Object sender, EventArgs e)
{
    String myString = "AllowNavigationChanged event raised, Navigation ";
    boolean myBool = myDataGrid.get_AllowNavigation();

    // Create appropriate alert message.
    myString = myString + ((myBool) ? " is " : " is not " + "allowed");

    // Show information about navigation.
    MessageBox.Show(myString, "Navigation information");
} //GridAllowNavChange

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

请参见

参考

DataGrid 类
DataGrid 成员
System.Windows.Forms 命名空间