Share via


DataGridColumnStyle.ReadOnlyChanged 事件

ReadOnly 属性值更改时发生。

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

语法

声明
Public Event ReadOnlyChanged As EventHandler
用法
Dim instance As DataGridColumnStyle
Dim handler As EventHandler

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

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

备注

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

示例

  Private Sub Button_Click(ByVal sender As Object, ByVal e As EventArgs)
      If myButton.Text = "Make column read/write" Then
          myDataGridColumnStyle.ReadOnly = False
          myButton.Text = "Make column read only"
      Else
          myDataGridColumnStyle.ReadOnly = True
          myButton.Text = "Make column read/write"
      End If
  End Sub 'Button_Click

Private Sub AddCustomDataTableStyle()
   myDataGridTableStyle = New DataGridTableStyle()
   myDataGridTableStyle.MappingName = "Customers"
   myDataGridColumnStyle = New DataGridTextBoxColumn()
   myDataGridColumnStyle.MappingName = "CustName"
   ' Add EventHandler function for readonlychanged event.
   AddHandler myDataGridColumnStyle.ReadOnlyChanged, AddressOf myDataGridColumnStyle_ReadOnlyChanged
   myDataGridColumnStyle.HeaderText = "Customer"
   myDataGridTableStyle.GridColumnStyles.Add(myDataGridColumnStyle)
   ' Add the 'DataGridTableStyle' instance to the 'DataGrid'.
   myDataGrid.TableStyles.Add(myDataGridTableStyle)
End Sub 'AddCustomDataTableStyle

  Private Sub myDataGridColumnStyle_ReadOnlyChanged(ByVal sender As Object, ByVal e As EventArgs)
      MessageBox.Show("'Readonly' property is changed")
  End Sub 'myDataGridColumnStyle_ReadOnlyChanged
private void Button_Click(Object sender, EventArgs e)
{ 
   if (myButton.Text == "Make column read/write")
   {
      myDataGridColumnStyle.ReadOnly = false;
      myButton.Text = "Make column read only";
   }
   else
   {
      myDataGridColumnStyle.ReadOnly = true;
      myButton.Text = "Make column read/write";
   }
}

private void AddCustomDataTableStyle()
{
   myDataGridTableStyle = new DataGridTableStyle();
   myDataGridTableStyle.MappingName = "Customers";
   myDataGridColumnStyle = new DataGridTextBoxColumn();
   myDataGridColumnStyle.MappingName= "CustName";
   // Add EventHandler function for readonlychanged event.
   myDataGridColumnStyle.ReadOnlyChanged += new EventHandler(myDataGridColumnStyle_ReadOnlyChanged);
   myDataGridColumnStyle.HeaderText = "Customer";
   myDataGridTableStyle.GridColumnStyles.Add(myDataGridColumnStyle);
   // Add the 'DataGridTableStyle' instance to the 'DataGrid'.
   myDataGrid.TableStyles.Add(myDataGridTableStyle);
}
private void myDataGridColumnStyle_ReadOnlyChanged(Object sender, EventArgs e)
{
   MessageBox.Show("'Readonly' property is changed");
}
private:
   void Button_Click( Object^ /*sender*/, EventArgs^ /*e*/ )
   {
      if ( myButton->Text->Equals( "Make column read/write" ) )
      {
         myDataGridColumnStyle->ReadOnly = false;
         myButton->Text = "Make column read only";
      }
      else
      {
         myDataGridColumnStyle->ReadOnly = true;
         myButton->Text = "Make column read/write";
      }
   }

   void AddCustomDataTableStyle()
   {
      myDataGridTableStyle = gcnew DataGridTableStyle;
      myDataGridTableStyle->MappingName = "Customers";
      myDataGridColumnStyle = gcnew DataGridTextBoxColumn;
      myDataGridColumnStyle->MappingName = "CustName";
      
      // Add EventHandler function for readonlychanged event.
      myDataGridColumnStyle->ReadOnlyChanged += gcnew EventHandler( this, &MyForm1::myDataGridColumnStyle_ReadOnlyChanged );
      myDataGridColumnStyle->HeaderText = "Customer";
      myDataGridTableStyle->GridColumnStyles->Add( myDataGridColumnStyle );
      
      // Add the 'DataGridTableStyle' instance to the 'DataGrid'.
      myDataGrid->TableStyles->Add( myDataGridTableStyle );
   }

   void myDataGridColumnStyle_ReadOnlyChanged( Object^ /*sender*/, EventArgs^ /*e*/ )
   {
      MessageBox::Show( "'Readonly' property is changed" );
   }
void Button_Click(Object sender, EventArgs e)
{
    if (myButton.get_Text().Equals("Make column read/write")) {
        myDataGridColumnStyle.set_ReadOnly(false);
        myButton.set_Text("Make column read only");
    }
    else {
        myDataGridColumnStyle.set_ReadOnly(true);
        myButton.set_Text("Make column read/write");
    }
} //Button_Click

private void AddCustomDataTableStyle()
{
    myDataGridTableStyle = new DataGridTableStyle();
    myDataGridTableStyle.set_MappingName("Customers");
    myDataGridColumnStyle = new DataGridTextBoxColumn();
    myDataGridColumnStyle.set_MappingName("CustName");

    // Add EventHandler function for readonlychanged event.
    myDataGridColumnStyle.add_ReadOnlyChanged(new EventHandler(
        myDataGridColumnStyle_ReadOnlyChanged));
    myDataGridColumnStyle.set_HeaderText("Customer");
    myDataGridTableStyle.get_GridColumnStyles().Add(myDataGridColumnStyle);

    // Add the 'DataGridTableStyle' instance to the 'DataGrid'.
    myDataGrid.get_TableStyles().Add(myDataGridTableStyle);
} //AddCustomDataTableStyle

void myDataGridColumnStyle_ReadOnlyChanged(Object sender, EventArgs e)
{
    MessageBox.Show("'Readonly' property is changed");
} //myDataGridColumnStyle_ReadOnlyChanged

平台

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

请参见

参考

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