Share via


DataGridColumnStyle.PropertyDescriptorChanged 事件

PropertyDescriptor 属性值更改时发生。

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

语法

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

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

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

备注

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

示例

 Private Sub myButton_Click(ByVal sender As Object, ByVal e As EventArgs)
     If TablesAlreadyAdded Then
         Return
     End If
     AddCustomDataTableStyle()
 End Sub 'myButton_Click

Private Sub AddCustomDataTableStyle()
   Dim myTableStyle As New DataGridTableStyle()
   ' Map DataGridTableStyle to a DataTable.
   myTableStyle.MappingName = "Orders"
   ' Get CurrencyManager object.
   Dim myCurrencyManager As CurrencyManager = CType(BindingContext(myDataSet, "Orders"), CurrencyManager)
   ' Use the CurrencyManager to get the PropertyDescriptor for column.
   Dim myPropertyDescriptor As PropertyDescriptor = myCurrencyManager.GetItemProperties()("Amount")
   ' Construct a 'DataGridColumnStyle' object changing its format to 'Currency'.
   Dim myColumnStyle As DataGridTextBoxColumn = New DataGridTextBoxColumn(myPropertyDescriptor, "c", True)
   ' Add EventHandler function for PropertyDescriptorChanged Event.
   AddHandler myColumnStyle.PropertyDescriptorChanged, AddressOf MyPropertyDescriptor_Changed
   myTableStyle.GridColumnStyles.Add(myColumnStyle)
   ' Add the DataGridTableStyle instance to the GridTableStylesCollection.
   myDataGrid.TableStyles.Add(myTableStyle)
   TablesAlreadyAdded = True
End Sub 'AddCustomDataTableStyle

 Private Sub MyPropertyDescriptor_Changed(ByVal sender As Object, ByVal e As EventArgs)
     myLabel.Text = "Property Descriptor Property of DataGridColumnStyle has changed"
 End Sub 'MyPropertyDescriptor_Changed
private void myButton_Click(object sender, EventArgs e)
{
   if(TablesAlreadyAdded) 
   {
      return;
   }
   AddCustomDataTableStyle();
}
private void AddCustomDataTableStyle()
{
   DataGridTableStyle myTableStyle = new DataGridTableStyle();
   // Map DataGridTableStyle to a DataTable.
   myTableStyle.MappingName = "Orders";
   // Get CurrencyManager object.
   CurrencyManager myCurrencyManager = (CurrencyManager)BindingContext[myDataSet,"Orders"];
   // Use the CurrencyManager to get the PropertyDescriptor for column.
   PropertyDescriptor myPropertyDescriptor = myCurrencyManager.GetItemProperties()["Amount"];
   // Construct a 'DataGridColumnStyle' object changing its format to 'Currency'.
   DataGridColumnStyle myColumnStyle =  new DataGridTextBoxColumn(myPropertyDescriptor,"c",true);
   // Add EventHandler function for PropertyDescriptorChanged Event.
   myColumnStyle.PropertyDescriptorChanged+=new System.EventHandler(MyPropertyDescriptor_Changed);
   myTableStyle.GridColumnStyles.Add(myColumnStyle);
   // Add the DataGridTableStyle instance to the GridTableStylesCollection. 
   myDataGrid.TableStyles.Add(myTableStyle);
   TablesAlreadyAdded=true;
}
private void MyPropertyDescriptor_Changed(object sender,EventArgs e)
{
   myLabel.Text="Property Descriptor Property of DataGridColumnStyle has changed";
}
private:
   void myButton_Click( Object^ /*sender*/, EventArgs^ /*e*/ )
   {
      if ( TablesAlreadyAdded )
      {
         return;
      }

      AddCustomDataTableStyle();
   }

   void AddCustomDataTableStyle()
   {
      DataGridTableStyle^ myTableStyle = gcnew DataGridTableStyle;
      
      // Map DataGridTableStyle to a DataTable.
      myTableStyle->MappingName = "Orders";
      
      // Get CurrencyManager object.
      CurrencyManager^ myCurrencyManager = dynamic_cast<CurrencyManager^>(BindingContext[myDataSet, "Orders"]);
      
      // Use the CurrencyManager to get the PropertyDescriptor for column.
      PropertyDescriptor^ myPropertyDescriptor = myCurrencyManager->GetItemProperties()[ "Amount" ];
      
      // Construct a 'DataGridColumnStyle' object changing its format to 'Currency'.
      DataGridColumnStyle^ myColumnStyle = gcnew DataGridTextBoxColumn( myPropertyDescriptor,"c",true );
      
      // Add EventHandler function for PropertyDescriptorChanged Event.
      myColumnStyle->PropertyDescriptorChanged += gcnew System::EventHandler( this, &myDataForm::MyPropertyDescriptor_Changed );
      myTableStyle->GridColumnStyles->Add( myColumnStyle );
      
      // Add the DataGridTableStyle instance to the GridTableStylesCollection.
      myDataGrid->TableStyles->Add( myTableStyle );
      TablesAlreadyAdded = true;
   }

   void MyPropertyDescriptor_Changed( Object^ /*sender*/, EventArgs^ /*e*/ )
   {
      myLabel->Text = "Property Descriptor Property of DataGridColumnStyle has changed";
   }
protected void myButton_Click(Object sender, EventArgs e)
{
    if (TablesAlreadyAdded) {
        return;
    }
    AddCustomDataTableStyle();
} //myButton_Click

private void AddCustomDataTableStyle()
{
    DataGridTableStyle myTableStyle = new DataGridTableStyle();

    // Map DataGridTableStyle to a DataTable.
    myTableStyle.set_MappingName("Orders");

    // Get CurrencyManager object.
    CurrencyManager myCurrencyManager = (CurrencyManager)
        get_BindingContext().get_Item(myDataSet, "Orders");

    // Use the CurrencyManager to get the PropertyDescriptor for column.
    PropertyDescriptor myPropertyDescriptor = 
        myCurrencyManager.GetItemProperties().get_Item("Amount");

    // Construct a 'DataGridColumnStyle' object changing its format to 
    // 'Currency'.
    DataGridColumnStyle myColumnStyle = 
        new DataGridTextBoxColumn(myPropertyDescriptor, "c", true);

    // Add EventHandler function for PropertyDescriptorChanged Event.
    myColumnStyle.add_PropertyDescriptorChanged(new System.EventHandler(
        MyPropertyDescriptorChanged));
    myTableStyle.get_GridColumnStyles().Add(myColumnStyle);

    // Add the DataGridTableStyle instance to the GridTableStylesCollection. 
    myDataGrid.get_TableStyles().Add(myTableStyle);
    TablesAlreadyAdded = true;
} //AddCustomDataTableStyle

void MyPropertyDescriptorChanged(Object sender, EventArgs e)
{
    myLabel.set_Text("Property Descriptor Property of " 
        + "DataGridColumnStyle has changed");
} //MyPropertyDescriptorChanged
protected void myButton_Click(Object sender, EventArgs e)
{
    if(TablesAlreadyAdded) {
        return;
    }
    AddCustomDataTableStyle();
} //myButton_Click

private void AddCustomDataTableStyle()
{
    DataGridTableStyle myTableStyle = new DataGridTableStyle();

    // Map DataGridTableStyle to a DataTable.
    myTableStyle.set_MappingName("Orders");

    // Get CurrencyManager object.
    CurrencyManager myCurrencyManager = (CurrencyManager)
        get_BindingContext().get_Item(myDataSet, "Orders");

    // Use the CurrencyManager to get the PropertyDescriptor for column.
    PropertyDescriptor myPropertyDescriptor = myCurrencyManager.
        GetItemProperties().get_Item("Amount");

    // Construct a 'DataGridColumnStyle' object changing its format to 
    // 'Currency'.
    DataGridColumnStyle myColumnStyle = 
        new DataGridTextBoxColumn(myPropertyDescriptor, "c", true);

    // Add EventHandler function for PropertyDescriptorChanged Event.
    myColumnStyle.add_PropertyDescriptorChanged(new System.
        EventHandler(MyPropertyDescriptorChanged));
    myTableStyle.get_GridColumnStyles().Add(myColumnStyle);

    // Add the DataGridTableStyle instance to the 
    // GridTableStylesCollection. 
    myDataGrid.get_TableStyles().Add(myTableStyle);
    TablesAlreadyAdded = true;
} //AddCustomDataTableStyle

void MyPropertyDescriptorChanged(Object sender, EventArgs e)
{
    myLabel.set_Text("Property Descriptor Property of " 
        + "DataGridColumnStyle has changed");
} //MyPropertyDescriptorChanged

平台

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 命名空间