DataGridView.CellStyleContentChanged 事件


儲存格樣式的其中一個值變更時發生。Occurs when one of the values of a cell style changes.

 event System::Windows::Forms::DataGridViewCellStyleContentChangedEventHandler ^ CellStyleContentChanged;
public event System.Windows.Forms.DataGridViewCellStyleContentChangedEventHandler CellStyleContentChanged;
member this.CellStyleContentChanged : System.Windows.Forms.DataGridViewCellStyleContentChangedEventHandler 
Public Custom Event CellStyleContentChanged As DataGridViewCellStyleContentChangedEventHandler 




下列程式碼範例將示範如何使用這個成員。The following code example demonstrates the use of this member. 在此範例中,事件處理常式會報告事件的發生情況 CellStyleContentChangedIn the example, an event handler reports on the occurrence of the CellStyleContentChanged event. 這份報告可協助您瞭解發生事件的時間,並協助您進行調試。This report helps you to learn when the event occurs and can assist you in debugging. 若要報告多個事件或經常發生的事件,請考慮將取代為 MessageBox.Show Console.WriteLine 或將訊息附加至多行 TextBoxTo report on multiple events or on events that occur frequently, consider replacing MessageBox.Show with Console.WriteLine or appending the message to a multiline TextBox.

若要執行範例程式碼,請將它貼到包含名為之類型實例的專案中 DataGridView DataGridView1To run the example code, paste it into a project that contains an instance of type DataGridView named DataGridView1. 然後確定事件處理常式與事件相關聯 CellStyleContentChangedThen ensure that the event handler is associated with the CellStyleContentChanged event.

private void DataGridView1_CellStyleContentChanged(Object sender, DataGridViewCellStyleContentChangedEventArgs e) {

System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "CellStyle", e.CellStyle );
messageBoxCS.AppendFormat("{0} = {1}", "CellStyleScope", e.CellStyleScope );
MessageBox.Show(messageBoxCS.ToString(), "CellStyleContentChanged Event" );
Private Sub DataGridView1_CellStyleContentChanged(sender as Object, e as DataGridViewCellStyleContentChangedEventArgs) _ 
     Handles DataGridView1.CellStyleContentChanged

    Dim messageBoxVB as New System.Text.StringBuilder()
    messageBoxVB.AppendFormat("{0} = {1}", "CellStyle", e.CellStyle)
    messageBoxVB.AppendFormat("{0} = {1}", "CellStyleScope", e.CellStyleScope)
    MessageBox.Show(messageBoxVB.ToString(),"CellStyleContentChanged Event")

End Sub


CellStyleContentChanged DataGridViewCellStyle 下列其中一個屬性所傳回之物件的屬性值變更時,就會發生此事件:The CellStyleContentChanged event occurs when a property value of a DataGridViewCellStyle object returned by one of the following properties changes:

但是,如果其中一個屬性設定為不同的 DataGridViewCellStyle ,則會發生對應的 PropertyName Changed 事件,但是 CellStyleContentChanged 不會發生此事件。If one of these properties is set to a different DataGridViewCellStyle, however, the corresponding PropertyNameChanged event occurs, but the CellStyleContentChanged event does not occur.

針對資料列、資料行和資料格屬性, PropertyName Changed 事件的名稱開頭為 " Row "、" Column " 或 " Cell " (例如 RowDefaultCellStyleChanged) 。For row, column, and cell properties, the name of the PropertyNameChanged event begins with "Row", "Column", or "Cell" (for example, RowDefaultCellStyleChanged).

如需如何處理事件的詳細資訊,請參閱 處理和引發事件For more information about how to handle events, see Handling and Raising Events.