Export (0) Print
Expand All

DataGridColumnStyle.PropertyDescriptorChanged Event

Occurs when the PropertyDescriptor property value changes.

[Visual Basic]
Public Event PropertyDescriptorChanged As EventHandler
[C#]
public event EventHandler PropertyDescriptorChanged;
[C++]
public: __event EventHandler* PropertyDescriptorChanged;

[JScript] In JScript, you can handle the events defined by a class, but you cannot define your own.

Event Data

The event handler receives an argument of type EventArgs.

Remarks

For more information about handling events, see Consuming Events.

Example

[Visual Basic] 
Protected 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

Sub MyPropertyDescriptor_Changed(ByVal sender As Object, ByVal e As EventArgs)
   myLabel.Text = "Property Descriptor Property of DataGridColumnStyle has changed"
End Sub 'MyPropertyDescriptor_Changed

[C#] 
protected 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;
}
void MyPropertyDescriptor_Changed(object sender,EventArgs e)
{
   myLabel.Text="Property Descriptor Property of DataGridColumnStyle has changed";
}

[C++] 
protected:
    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 = S"Orders";
        // Get CurrencyManager object.
        CurrencyManager* myCurrencyManager = dynamic_cast<CurrencyManager*>(BindingContext->get_Item(myDataSet, S"Orders"));
        // Use the CurrencyManager to get the PropertyDescriptor for column.
        PropertyDescriptor* myPropertyDescriptor = myCurrencyManager->GetItemProperties()->Item[S"Amount"];
        // Construct a 'DataGridColumnStyle' object changing its format to 'Currency'.
        DataGridColumnStyle* myColumnStyle = new DataGridTextBoxColumn(myPropertyDescriptor, S"c", true);
        // Add EventHandler function for PropertyDescriptorChanged Event.
        myColumnStyle->PropertyDescriptorChanged += new 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=S"Property Descriptor Property of DataGridColumnStyle has changed";
    }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

DataGridColumnStyle Class | DataGridColumnStyle Members | System.Windows.Forms Namespace

Show:
© 2014 Microsoft