DataGridColumnStyle.HeaderTextChanged 事件
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
發生在 HeaderText 屬性值變更時。
public:
event EventHandler ^ HeaderTextChanged;
public event EventHandler HeaderTextChanged;
member this.HeaderTextChanged : EventHandler
Public Custom Event HeaderTextChanged As EventHandler
事件類型
範例
下列程式碼範例示範如何使用這個成員。
private:
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 the column.
PropertyDescriptor^ myPropertyDescriptor = myCurrencyManager->GetItemProperties()[ "Amount" ];
// Change the HeaderText.
DataGridColumnStyle^ myColumnStyle = gcnew DataGridTextBoxColumn( myPropertyDescriptor,"c",true );
// Attach a event handler function with the 'HeaderTextChanged' event.
myColumnStyle->HeaderTextChanged += gcnew EventHandler( this, &myDataForm::MyHeaderText_Changed );
myColumnStyle->Width = 130;
myColumnStyle->HeaderText = "Amount in $";
myTableStyle->GridColumnStyles->Add( myColumnStyle );
myDataGrid->TableStyles->Add( myTableStyle );
TablesAlreadyAdded = (bool *)true;
}
void MyHeaderText_Changed( Object^ /*sender*/, EventArgs^ /*e*/ )
{
myLabel->Text = "Header Descriptor Property of DataGridColumnStyle has changed";
}
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 the column.
PropertyDescriptor myPropertyDescriptor = myCurrencyManager.GetItemProperties()["Amount"];
// Change the HeaderText.
DataGridColumnStyle myColumnStyle = new DataGridTextBoxColumn(myPropertyDescriptor,"c",true);
// Attach a event handler function with the 'HeaderTextChanged' event.
myColumnStyle.HeaderTextChanged+=new EventHandler(MyHeaderText_Changed);
myColumnStyle.Width=130;
myColumnStyle.HeaderText="Amount in $";
myTableStyle.GridColumnStyles.Add(myColumnStyle);
myDataGrid.TableStyles.Add(myTableStyle);
TablesAlreadyAdded=true;
}
private void MyHeaderText_Changed(object sender,EventArgs e)
{
myLabel.Text="Header Descriptor Property of DataGridColumnStyle has changed";
}
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 the column.
Dim myPropertyDescriptor As PropertyDescriptor = myCurrencyManager.GetItemProperties()("Amount")
' Change the HeaderText.
Dim myColumnStyle As DataGridTextBoxColumn = New DataGridTextBoxColumn(myPropertyDescriptor, "c", True)
' Attach a event handler function with the 'HeaderTextChanged' event.
AddHandler myColumnStyle.HeaderTextChanged, AddressOf MyHeaderText_Changed
myColumnStyle.Width = 130
myColumnStyle.HeaderText = "Amount in $"
myTableStyle.GridColumnStyles.Add(myColumnStyle)
myDataGrid.TableStyles.Add(myTableStyle)
TablesAlreadyAdded = True
End Sub
Private Sub MyHeaderText_Changed(ByVal sender As Object, ByVal e As EventArgs)
myLabel.Text = "Header Descriptor Property of DataGridColumnStyle has changed"
End Sub