DataGridColumnStyle イベント

名前 | 説明 | |
---|---|---|
![]() | Disposed | コンポーネントの Disposed イベントを待機するイベント ハンドラを追加します。 ( Component から継承されます。) |
![]() | FontChanged | 列のフォントが変更されたときに発生します。 |
![]() | HeaderTextChanged | HeaderText プロパティの値が変更された場合に発生します。 |
![]() | MappingNameChanged | MappingName の値が変更された場合に発生します。 |
![]() | NullTextChanged | NullText の値が変更された場合に発生します。 |
![]() | PropertyDescriptorChanged | PropertyDescriptor プロパティの値が変更された場合に発生します。 |
![]() | ReadOnlyChanged | ReadOnly プロパティの値が変更された場合に発生します。 |
![]() | WidthChanged | Width プロパティの値が変更された場合に発生します。 |

DataGridColumnStyle クラス
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Public MustInherit Class DataGridColumnStyle Inherits Component Implements IDataGridColumnStyleEditingNotificationService
public abstract class DataGridColumnStyle : Component, IDataGridColumnStyleEditingNotificationService
public ref class DataGridColumnStyle abstract : public Component, IDataGridColumnStyleEditingNotificationService

DataGridColumnStyle オブジェクトのコレクション (GridColumnStylesCollection) は、System.Windows.Forms.DataGrid コントロールの TableStyles プロパティを通じてアクセスします。
System.Windows.Forms.DataGrid コントロールでは、DataSource プロパティを適切なデータ ソースに設定すると、DataGridColumnStyle オブジェクトのコレクションが自動的に作成されます。作成されたオブジェクトは、実際には DataGridColumnStyle クラスから継承された、DataGridBoolColumn または DataGridTextBoxColumn のいずれかのクラスのインスタンスです。
データ表示の書式を指定するには、DataGridTextBoxColumn クラスの Format プロパティを書式指定値のいずれかに設定します。有効な書式指定値の詳細については、「日付と時刻の書式指定文字列」と「標準の数値書式指定文字列」を参照してください。
独自の DataGridColumnStyle オブジェクト セットを作成し、それらのオブジェクトを GridColumnStylesCollection に追加することもできます。この操作を行うときは、各列スタイルの MappingName を DataColumn の ColumnName に設定して、実際のデータと列の表示を同期させます。
![]() |
---|
必ず DataGridColumnStyle オブジェクトを作成して GridColumnStylesCollection に追加してから、DataGridTableStyle オブジェクトを GridTableStylesCollection に追加します。有効な MappingName 値を持つ空の DataGridTableStyle をコレクションに追加すると、自動的に DataGridColumnStyle オブジェクトが生成されます。そのため、MappingName 値が重複する新しい DataGridColumnStyle オブジェクトを GridColumnStylesCollection に追加しようとすると、例外がスローされます。 |
System.Windows.Forms.DataGrid コントロールによって派生クラスのいずれかがインスタンス化される場合、作成されるクラスは、DataGridColumnStyle オブジェクトに関連付けられた DataColumn の DataType によって異なります。たとえば、DataType が System.Boolean に設定された DataColumn は、DataGridBoolColumn に関連付けられます。DataGridColumnStyle の型を確認するには、GetType メソッドを使用します。
独自の列クラスを作成するには、DataGridColumnStyle から継承できます。TextBox コントロールをホストする DataGridTextBox クラスの場合のように、コントロールをホストする特別な列を作成するために独自の列クラスを作成できます。たとえば、Image コントロールをホストして列にイメージを表示したり、独自のユーザー コントロールを作成して列でホストしたりできます。
DataGridColumnStyle の機能は、DataColumn の機能とは異なります。DataColumn がデータ テーブルのスキーマの作成に使用するプロパティおよびメソッドを格納しているのに対し、DataGridColumnStyle は画面上の各列の外観に関連するプロパティおよびメソッドを格納しています。
行が DBNull.Value を格納している場合、列に表示されるテキストは NullText プロパティを使用して設定できます。
DataGridColumnStyle クラスを使用すると、データを変更中に列の動作を指定することもできます。BeginUpdate メソッドと EndUpdate メソッドは、列のデータに対して大規模な更新が行われている間、一時的に列の描画を中断します。この機能を使用しない場合、グリッドの各セルが変更されるたびに描画されるため、ユーザーがストレスを感じたり、パフォーマンスが低下したりします。
Edit イベント、Commit イベントなどのメソッドを使用すると、ユーザーが編集する列を監視できます。
このクラスのプロパティおよびメソッドの多くは、列の外観を制御するために使用されます。ただし、GetColumnValueAtRow や SetColumnValueAtRow などのメソッドは、指定したセルの値を調べたり、変更したりできます。
実装時の注意 DataGridColumnStyle から継承する場合は、Abort、Commit、Edit、Paint (2 回) の各メンバをオーバーライドする必要があります。
DateTimePicker コントロールをホストする DataGridColumnStyle を作成するコード例を次に示します。
Imports System Imports System.Data Imports System.Windows.Forms Imports System.Drawing Imports System.ComponentModel Imports System.Security.Permissions ' This example shows how to create your own column style that ' hosts a control, in this case, a DateTimePicker. Public Class DataGridTimePickerColumn Inherits DataGridColumnStyle Private customDateTimePicker1 As New CustomDateTimePicker() ' The isEditing field tracks whether or not the user is ' editing data with the hosted control. Private isEditing As Boolean Public Sub New() customDateTimePicker1.Visible = False End Sub Protected Overrides Sub Abort(ByVal rowNum As Integer) isEditing = False RemoveHandler customDateTimePicker1.ValueChanged, _ AddressOf TimePickerValueChanged Invalidate() End Sub Protected Overrides Function Commit _ (ByVal dataSource As CurrencyManager, ByVal rowNum As Integer) _ As Boolean customDateTimePicker1.Bounds = Rectangle.Empty RemoveHandler customDateTimePicker1.ValueChanged, _ AddressOf TimePickerValueChanged If Not isEditing Then Return True End If isEditing = False Try Dim value As DateTime = customDateTimePicker1.Value SetColumnValueAtRow(dataSource, rowNum, value) Catch End Try Invalidate() Return True End Function Protected Overloads Overrides Sub Edit( _ ByVal [source] As CurrencyManager, _ ByVal rowNum As Integer, _ ByVal bounds As Rectangle, _ ByVal [readOnly] As Boolean, _ ByVal displayText As String, _ ByVal cellIsVisible As Boolean) Dim value As DateTime = _ CType(GetColumnValueAtRow([source], rowNum), DateTime) If cellIsVisible Then customDateTimePicker1.Bounds = New Rectangle _ (bounds.X + 2, bounds.Y + 2, bounds.Width - 4, _ bounds.Height - 4) customDateTimePicker1.Value = value customDateTimePicker1.Visible = True AddHandler customDateTimePicker1.ValueChanged, _ AddressOf TimePickerValueChanged Else customDateTimePicker1.Value = value customDateTimePicker1.Visible = False End If If customDateTimePicker1.Visible Then DataGridTableStyle.DataGrid.Invalidate(bounds) End If customDateTimePicker1.Focus() End Sub Protected Overrides Function GetPreferredSize( _ ByVal g As Graphics, _ ByVal value As Object) As Size Return New Size(100, customDateTimePicker1.PreferredHeight + 4) End Function Protected Overrides Function GetMinimumHeight() As Integer Return customDateTimePicker1.PreferredHeight + 4 End Function Protected Overrides Function GetPreferredHeight( _ ByVal g As Graphics, ByVal value As Object) As Integer Return customDateTimePicker1.PreferredHeight + 4 End Function Protected Overloads Overrides Sub Paint( _ ByVal g As Graphics, ByVal bounds As Rectangle, _ ByVal [source] As CurrencyManager, ByVal rowNum As Integer) Paint(g, bounds, [source], rowNum, False) End Sub Protected Overloads Overrides Sub Paint(ByVal g As Graphics, _ ByVal bounds As Rectangle, ByVal [source] As CurrencyManager, _ ByVal rowNum As Integer, ByVal alignToRight As Boolean) Paint(g, bounds, [source], rowNum, Brushes.Red, _ Brushes.Blue, alignToRight) End Sub Protected Overloads Overrides Sub Paint(ByVal g As Graphics, _ ByVal bounds As Rectangle, ByVal [source] As CurrencyManager, _ ByVal rowNum As Integer, ByVal backBrush As Brush, _ ByVal foreBrush As Brush, ByVal alignToRight As Boolean) Dim [date] As DateTime = _ CType(GetColumnValueAtRow([source], rowNum), DateTime) Dim rect As Rectangle = bounds g.FillRectangle(backBrush, rect) rect.Offset(0, 2) rect.Height -= 2 g.DrawString([date].ToString("d"), _ Me.DataGridTableStyle.DataGrid.Font, foreBrush, _ RectangleF.FromLTRB(rect.X, rect.Y, rect.Right, rect.Bottom)) End Sub Protected Overrides Sub SetDataGridInColumn(ByVal value As DataGrid) MyBase.SetDataGridInColumn(value) If Not (customDateTimePicker1.Parent Is Nothing) Then customDateTimePicker1.Parent.Controls.Remove(customDateTimePicker1) End If If Not (value Is Nothing) Then value.Controls.Add(customDateTimePicker1) End If End Sub Private Sub TimePickerValueChanged( _ ByVal sender As Object, ByVal e As EventArgs) ' Remove the handler to prevent it from being called twice in a row. RemoveHandler customDateTimePicker1.ValueChanged, _ AddressOf TimePickerValueChanged Me.isEditing = True MyBase.ColumnStartedEditing(customDateTimePicker1) End Sub End Class Public Class CustomDateTimePicker Inherits DateTimePicker <SecurityPermissionAttribute( _ SecurityAction.LinkDemand, Flags := SecurityPermissionFlag.UnmanagedCode)> _ Protected Overrides Function ProcessKeyMessage(ByRef m As Message) As Boolean ' Keep all the keys for the DateTimePicker. Return ProcessKeyEventArgs(m) End Function End Class Public Class MyForm Inherits Form Private namesDataTable As DataTable Private myGrid As DataGrid = New DataGrid() Public Sub New() InitForm() namesDataTable = New DataTable("NamesTable") namesDataTable.Columns.Add(New DataColumn("Name")) Dim dateColumn As DataColumn = _ New DataColumn("Date", GetType(DateTime)) dateColumn.DefaultValue = DateTime.Today namesDataTable.Columns.Add(dateColumn) Dim namesDataSet As DataSet = New DataSet() namesDataSet.Tables.Add(namesDataTable) myGrid.DataSource = namesDataSet myGrid.DataMember = "NamesTable" AddGridStyle() AddData() End Sub Private Sub AddGridStyle() Dim myGridStyle As DataGridTableStyle = _ New DataGridTableStyle() myGridStyle.MappingName = "NamesTable" Dim nameColumnStyle As DataGridTextBoxColumn = _ New DataGridTextBoxColumn() nameColumnStyle.MappingName = "Name" nameColumnStyle.HeaderText = "Name" myGridStyle.GridColumnStyles.Add(nameColumnStyle) Dim customDateTimePicker1ColumnStyle As DataGridTimePickerColumn = _ New DataGridTimePickerColumn() customDateTimePicker1ColumnStyle.MappingName = "Date" customDateTimePicker1ColumnStyle.HeaderText = "Date" customDateTimePicker1ColumnStyle.Width = 100 myGridStyle.GridColumnStyles.Add(customDateTimePicker1ColumnStyle) myGrid.TableStyles.Add(myGridStyle) End Sub Private Sub AddData() Dim dRow As DataRow = namesDataTable.NewRow() dRow("Name") = "Name 1" dRow("Date") = New DateTime(2001, 12, 1) namesDataTable.Rows.Add(dRow) dRow = namesDataTable.NewRow() dRow("Name") = "Name 2" dRow("Date") = New DateTime(2001, 12, 4) namesDataTable.Rows.Add(dRow) dRow = namesDataTable.NewRow() dRow("Name") = "Name 3" dRow("Date") = New DateTime(2001, 12, 29) namesDataTable.Rows.Add(dRow) dRow = namesDataTable.NewRow() dRow("Name") = "Name 4" dRow("Date") = New DateTime(2001, 12, 13) namesDataTable.Rows.Add(dRow) dRow = namesDataTable.NewRow() dRow("Name") = "Name 5" dRow("Date") = New DateTime(2001, 12, 21) namesDataTable.Rows.Add(dRow) namesDataTable.AcceptChanges() End Sub Private Sub InitForm() Me.Size = New Size(500, 500) myGrid.Size = New Size(350, 250) myGrid.TabStop = True myGrid.TabIndex = 1 Me.StartPosition = FormStartPosition.CenterScreen Me.Controls.Add(myGrid) End Sub <STAThread()> _ Public Shared Sub Main() Application.Run(New MyForm()) End Sub End Class
using System; using System.Data; using System.Windows.Forms; using System.Drawing; using System.Security.Permissions; // This example shows how to create your own column style that // hosts a control, in this case, a DateTimePicker. public class DataGridTimePickerColumn : DataGridColumnStyle { private CustomDateTimePicker customDateTimePicker1 = new CustomDateTimePicker(); // The isEditing field tracks whether or not the user is // editing data with the hosted control. private bool isEditing; public DataGridTimePickerColumn() : base() { customDateTimePicker1.Visible = false; } protected override void Abort(int rowNum) { isEditing = false; customDateTimePicker1.ValueChanged -= new EventHandler(TimePickerValueChanged); Invalidate(); } protected override bool Commit (CurrencyManager dataSource, int rowNum) { customDateTimePicker1.Bounds = Rectangle.Empty; customDateTimePicker1.ValueChanged -= new EventHandler(TimePickerValueChanged); if (!isEditing) return true; isEditing = false; try { DateTime value = customDateTimePicker1.Value; SetColumnValueAtRow(dataSource, rowNum, value); } catch (Exception) { Abort(rowNum); return false; } Invalidate(); return true; } protected override void Edit( CurrencyManager source, int rowNum, Rectangle bounds, bool readOnly, string displayText, bool cellIsVisible) { DateTime value = (DateTime) GetColumnValueAtRow(source, rowNum); if (cellIsVisible) { customDateTimePicker1.Bounds = new Rectangle (bounds.X + 2, bounds.Y + 2, bounds.Width - 4, bounds.Height - 4); customDateTimePicker1.Value = value; customDateTimePicker1.Visible = true; customDateTimePicker1.ValueChanged += new EventHandler(TimePickerValueChanged); } else { customDateTimePicker1.Value = value; customDateTimePicker1.Visible = false; } if (customDateTimePicker1.Visible) DataGridTableStyle.DataGrid.Invalidate(bounds); customDateTimePicker1.Focus(); } protected override Size GetPreferredSize( Graphics g, object value) { return new Size(100, customDateTimePicker1.PreferredHeight + 4); } protected override int GetMinimumHeight() { return customDateTimePicker1.PreferredHeight + 4; } protected override int GetPreferredHeight(Graphics g, object value) { return customDateTimePicker1.PreferredHeight + 4; } protected override void Paint(Graphics g, Rectangle bounds, CurrencyManager source, int rowNum) { Paint(g, bounds, source, rowNum, false); } protected override void Paint( Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, bool alignToRight) { Paint( g, bounds, source, rowNum, Brushes.Red, Brushes.Blue, alignToRight); } protected override void Paint( Graphics g, Rectangle bounds, CurrencyManager source, int rowNum, Brush backBrush, Brush foreBrush, bool alignToRight) { DateTime date = (DateTime) GetColumnValueAtRow(source, rowNum); Rectangle rect = bounds; g.FillRectangle(backBrush, rect); rect.Offset(0, 2); rect.Height -= 2; g.DrawString(date.ToString("d"), this.DataGridTableStyle.DataGrid.Font, foreBrush, rect); } protected override void SetDataGridInColumn(DataGrid value) { base.SetDataGridInColumn(value); if (customDateTimePicker1.Parent != null) { customDateTimePicker1.Parent.Controls.Remove (customDateTimePicker1); } if (value != null) { value.Controls.Add(customDateTimePicker1); } } private void TimePickerValueChanged(object sender, EventArgs e) { // Remove the handler to prevent it from being called twice in a row. customDateTimePicker1.ValueChanged -= new EventHandler(TimePickerValueChanged); this.isEditing = true; base.ColumnStartedEditing(customDateTimePicker1); } } public class CustomDateTimePicker : DateTimePicker { [SecurityPermissionAttribute( SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.UnmanagedCode)] protected override bool ProcessKeyMessage(ref Message m) { // Keep all the keys for the DateTimePicker. return ProcessKeyEventArgs(ref m); } } public class MyForm : Form { private DataTable namesDataTable; private DataGrid grid = new DataGrid(); public MyForm() : base() { InitForm(); namesDataTable = new DataTable("NamesTable"); namesDataTable.Columns.Add(new DataColumn("Name")); DataColumn dateColumn = new DataColumn ("Date", typeof(DateTime)); dateColumn.DefaultValue = DateTime.Today; namesDataTable.Columns.Add(dateColumn); DataSet namesDataSet = new DataSet(); namesDataSet.Tables.Add(namesDataTable); grid.DataSource = namesDataSet; grid.DataMember = "NamesTable"; AddGridStyle(); AddData(); } private void AddGridStyle() { DataGridTableStyle myGridStyle = new DataGridTableStyle(); myGridStyle.MappingName = "NamesTable"; DataGridTextBoxColumn nameColumnStyle = new DataGridTextBoxColumn(); nameColumnStyle.MappingName = "Name"; nameColumnStyle.HeaderText = "Name"; myGridStyle.GridColumnStyles.Add(nameColumnStyle); DataGridTimePickerColumn timePickerColumnStyle = new DataGridTimePickerColumn(); timePickerColumnStyle.MappingName = "Date"; timePickerColumnStyle.HeaderText = "Date"; timePickerColumnStyle.Width = 100; myGridStyle.GridColumnStyles.Add(timePickerColumnStyle); grid.TableStyles.Add(myGridStyle); } private void AddData() { DataRow dRow = namesDataTable.NewRow(); dRow["Name"] = "Name 1"; dRow["Date"] = new DateTime(2001, 12, 01); namesDataTable.Rows.Add(dRow); dRow = namesDataTable.NewRow(); dRow["Name"] = "Name 2"; dRow["Date"] = new DateTime(2001, 12, 04); namesDataTable.Rows.Add(dRow); dRow = namesDataTable.NewRow(); dRow["Name"] = "Name 3"; dRow["Date"] = new DateTime(2001, 12, 29); namesDataTable.Rows.Add(dRow); dRow = namesDataTable.NewRow(); dRow["Name"] = "Name 4"; dRow["Date"] = new DateTime(2001, 12, 13); namesDataTable.Rows.Add(dRow); dRow = namesDataTable.NewRow(); dRow["Name"] = "Name 5"; dRow["Date"] = new DateTime(2001, 12, 21); namesDataTable.Rows.Add(dRow); namesDataTable.AcceptChanges(); } private void InitForm() { this.Size = new Size(500, 500); grid.Size = new Size(350, 250); grid.TabStop = true; grid.TabIndex = 1; this.StartPosition = FormStartPosition.CenterScreen; this.Controls.Add(grid); } [STAThread] public static void Main() { MyForm myForm1 = new MyForm(); myForm1.ShowDialog(); } }
#using <System.dll> #using <System.Data.dll> #using <System.Drawing.dll> #using <System.Windows.Forms.dll> #using <System.Xml.dll> using namespace System; using namespace System::Data; using namespace System::Windows::Forms; using namespace System::Drawing; using namespace System::Security::Permissions; // This example shows how to create your own column style that // hosts a control, in this case, a DateTimePicker. public ref class CustomDateTimePicker : public DateTimePicker { protected: [SecurityPermission(SecurityAction::Demand, Flags=SecurityPermissionFlag::UnmanagedCode)] virtual bool ProcessKeyMessage( Message% m ) override { // Keep all the keys for the DateTimePicker. return ProcessKeyEventArgs( m ); } }; public ref class DataGridTimePickerColumn : public DataGridColumnStyle { private: CustomDateTimePicker^ customDateTimePicker1; // The isEditing field tracks whether or not the user is // editing data with the hosted control. bool isEditing; public: DataGridTimePickerColumn() { customDateTimePicker1 = gcnew CustomDateTimePicker; customDateTimePicker1->Visible = false; } protected: virtual void Abort( int /*rowNum*/ ) override { isEditing = false; customDateTimePicker1->ValueChanged -= gcnew EventHandler( this, &DataGridTimePickerColumn::TimePickerValueChanged ); Invalidate(); } virtual bool Commit( CurrencyManager^ dataSource, int rowNum ) override { customDateTimePicker1->Bounds = Rectangle::Empty; customDateTimePicker1->ValueChanged -= gcnew EventHandler( this, &DataGridTimePickerColumn::TimePickerValueChanged ); if ( !isEditing ) return true; isEditing = false; try { DateTime value = customDateTimePicker1->Value; SetColumnValueAtRow( dataSource, rowNum, value ); } catch ( Exception^ ) { Abort( rowNum ); return false; } Invalidate(); return true; } virtual void Edit( CurrencyManager^ source, int rowNum, Rectangle bounds, bool /*readOnly*/, String^ /*displayText*/, bool cellIsVisible ) override { DateTime value = (DateTime) GetColumnValueAtRow( source, rowNum ); if ( cellIsVisible ) { customDateTimePicker1->Bounds = Rectangle( bounds.X + 2, bounds.Y + 2, bounds.Width - 4, bounds.Height - 4 ); customDateTimePicker1->Value = value; customDateTimePicker1->Visible = true; customDateTimePicker1->ValueChanged += gcnew EventHandler( this, &DataGridTimePickerColumn::TimePickerValueChanged ); } else { customDateTimePicker1->Value = value; customDateTimePicker1->Visible = false; } if ( customDateTimePicker1->Visible ) DataGridTableStyle->DataGrid->Invalidate( bounds ); customDateTimePicker1->Focus(); } virtual System::Drawing::Size GetPreferredSize( Graphics^ /*g*/, Object^ /*value*/ ) override { return Size( 100, customDateTimePicker1->PreferredHeight + 4); } virtual int GetMinimumHeight() override { return customDateTimePicker1->PreferredHeight + 4; } virtual int GetPreferredHeight( Graphics^ /*g*/, Object^ /*value*/ ) override { return customDateTimePicker1->PreferredHeight + 4; } virtual void Paint( Graphics^ g, Rectangle bounds, CurrencyManager^ source, int rowNum ) override { Paint( g, bounds, source, rowNum, false ); } virtual void Paint( Graphics^ g, Rectangle bounds, CurrencyManager^ source, int rowNum, bool alignToRight ) override { Paint( g, bounds, source, rowNum, Brushes::Red, Brushes::Blue, alignToRight ); } virtual void Paint( Graphics^ g, Rectangle bounds, CurrencyManager^ source, int rowNum, Brush^ backBrush, Brush^ foreBrush, bool /*alignToRight*/ ) override { DateTime date = (DateTime) GetColumnValueAtRow( source, rowNum ); Rectangle rect = bounds; g->FillRectangle( backBrush, rect ); rect.Offset( 0, 2 ); rect.Height -= 2; g->DrawString( date.ToString( "d" ), this->DataGridTableStyle->DataGrid->Font, foreBrush, rect ); } virtual void SetDataGridInColumn( DataGrid^ value ) override { DataGridColumnStyle::SetDataGridInColumn( value ); if ( customDateTimePicker1->Parent != nullptr ) { customDateTimePicker1->Parent->Controls->Remove ( customDateTimePicker1 ); } if ( value != nullptr ) { value->Controls->Add( customDateTimePicker1 ); } } private: void TimePickerValueChanged( Object^ /*sender*/, EventArgs^ /*e*/ ) { // Remove the handler to prevent it from being called twice in a row. customDateTimePicker1->ValueChanged -= gcnew EventHandler( this, &DataGridTimePickerColumn::TimePickerValueChanged ); this->isEditing = true; DataGridColumnStyle::ColumnStartedEditing( customDateTimePicker1 ); } }; public ref class MyForm: public Form { private: DataTable^ namesDataTable; DataGrid^ grid; public: MyForm() { grid = gcnew DataGrid; InitForm(); namesDataTable = gcnew DataTable( "NamesTable" ); namesDataTable->Columns->Add( gcnew DataColumn( "Name" ) ); DataColumn^ dateColumn = gcnew DataColumn ( "Date",DateTime::typeid ); dateColumn->DefaultValue = DateTime::Today; namesDataTable->Columns->Add( dateColumn ); DataSet^ namesDataSet = gcnew DataSet; namesDataSet->Tables->Add( namesDataTable ); grid->DataSource = namesDataSet; grid->DataMember = "NamesTable"; AddGridStyle(); AddData(); } private: void AddGridStyle() { DataGridTableStyle^ myGridStyle = gcnew DataGridTableStyle; myGridStyle->MappingName = "NamesTable"; DataGridTextBoxColumn^ nameColumnStyle = gcnew DataGridTextBoxColumn; nameColumnStyle->MappingName = "Name"; nameColumnStyle->HeaderText = "Name"; myGridStyle->GridColumnStyles->Add( nameColumnStyle ); DataGridTimePickerColumn^ timePickerColumnStyle = gcnew DataGridTimePickerColumn; timePickerColumnStyle->MappingName = "Date"; timePickerColumnStyle->HeaderText = "Date"; timePickerColumnStyle->Width = 100; myGridStyle->GridColumnStyles->Add( timePickerColumnStyle ); grid->TableStyles->Add( myGridStyle ); } void AddData() { DataRow^ dRow = namesDataTable->NewRow(); dRow->default[ "Name" ] = "Name 1"; dRow->default[ "Date" ] = DateTime(2001,12 ,01); namesDataTable->Rows->Add( dRow ); dRow = namesDataTable->NewRow(); dRow->default[ "Name" ] = "Name 2"; dRow->default[ "Date" ] = DateTime(2001,12 ,04); namesDataTable->Rows->Add( dRow ); dRow = namesDataTable->NewRow(); dRow->default[ "Name" ] = "Name 3"; dRow->default[ "Date" ] = DateTime(2001,12 ,29); namesDataTable->Rows->Add( dRow ); dRow = namesDataTable->NewRow(); dRow->default[ "Name" ] = "Name 4"; dRow->default[ "Date" ] = DateTime(2001,12 ,13); namesDataTable->Rows->Add( dRow ); dRow = namesDataTable->NewRow(); dRow->default[ "Name" ] = "Name 5"; dRow->default[ "Date" ] = DateTime(2001,12 ,21); namesDataTable->Rows->Add( dRow ); namesDataTable->AcceptChanges(); } void InitForm() { this->Size = System::Drawing::Size( 500, 500 ); grid->Size = System::Drawing::Size( 350, 250 ); grid->TabStop = true; grid->TabIndex = 1; this->StartPosition = FormStartPosition::CenterScreen; this->Controls->Add( grid ); } }; [STAThread] int main() { MyForm^ myForm1 = gcnew MyForm; myForm1->ShowDialog(); }

System.MarshalByRefObject
System.ComponentModel.Component
System.Windows.Forms.DataGridColumnStyle
Microsoft.CLRAdmin.DataGridComboBoxColumnStyle
System.Windows.Forms.DataGridBoolColumn
System.Windows.Forms.DataGridTextBoxColumn


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DataGridColumnStyle コンストラクタ ()
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)



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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DataGridColumnStyle コンストラクタ (PropertyDescriptor)
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)


新しい DataGridColumnStyle を作成するには、最初に列を追加するテーブルのデータ ソースの CurrencyManager を取得する必要があります。フォームの特定の CurrencyManager オブジェクトを取得する方法については、CurrencyManager および BindingManager のトピックを参照してください。
CurrencyManager から、列のデータを提供する DataColumn の PropertyDescriptor を取得できます。
DataGridColumnStyle のインスタンスを作成すると、次の読み書き可能プロパティが初期化されます。

新しい DataGridTextBoxColumn (DataGridColumnStyle から派生) を作成し、DataGridTableStyle の GridColumnStylesCollection に追加するコード例を次に示します。
Private Sub CreateNewDataGridColumnStyle() Dim myDataSet As New DataSet("myDataSet") ' Insert code to populate the DataSet. ' Get the CurrencyManager for the table you want to add a column to. Dim myCurrencyManager As CurrencyManager = CType _ (Me.BindingContext(myDataSet.Tables("Suppliers")), CurrencyManager) ' Get the PropertyDescriptor for the DataColumn. Dim pd As PropertyDescriptor = _ myCurrencyManager.GetItemProperties()("City") ' Construct the DataGridColumnStyle with the PropertyDescriptor. Dim myColumn As New DataGridTextBoxColumn(pd) myColumn.MappingName = "City" dataGrid1.TableStyles(0).GridColumnStyles.Add(myColumn) End Sub
private void CreateNewDataGridColumnStyle(){ DataSet myDataSet = new DataSet("myDataSet"); // Insert code to populate the DataSet. // Get the CurrencyManager for the table you want to add a column to. CurrencyManager myCurrencyManager = (CurrencyManager)this.BindingContext[myDataSet, "Suppliers"]; // Get the PropertyDescriptor for the DataColumn. PropertyDescriptor pd = myCurrencyManager.GetItemProperties()["City"]; // Construct the DataGridColumnStyle with the PropertyDescriptor. DataGridColumnStyle myColumn = new DataGridTextBoxColumn(pd); myColumn.MappingName = "City"; dataGrid1.TableStyles[0].GridColumnStyles.Add(myColumn); }
void CreateNewDataGridColumnStyle() { DataSet^ myDataSet = gcnew DataSet( "myDataSet" ); // Insert code to populate the DataSet. // Get the CurrencyManager for the table you want to add a column to. CurrencyManager^ myCurrencyManager = dynamic_cast<CurrencyManager^>(this->BindingContext[myDataSet, "Suppliers"]); // Get the PropertyDescriptor for the DataColumn. PropertyDescriptor^ pd = myCurrencyManager->GetItemProperties()[ "City" ]; // Construct the DataGridColumnStyle with the PropertyDescriptor. DataGridColumnStyle^ myColumn = gcnew DataGridTextBoxColumn( pd ); myColumn->MappingName = "City"; dataGrid1->TableStyles[ 0 ]->GridColumnStyles->Add( myColumn ); }
private void CreateNewDataGridColumnStyle() { DataSet myDataSet = new DataSet("myDataSet"); // Insert code to populate the DataSet. // Get the CurrencyManager for the table you want to add a column to. CurrencyManager myCurrencyManager = (CurrencyManager)(this.get_BindingContext(). get_Item(myDataSet, "Suppliers")); // Get the PropertyDescriptor for the DataColumn. PropertyDescriptor pd = myCurrencyManager.GetItemProperties(). get_Item("City"); // Construct the DataGridColumnStyle with the PropertyDescriptor. DataGridColumnStyle myColumn = new DataGridTextBoxColumn(pd); myColumn.set_MappingName("City"); dataGrid1.get_TableStyles().get_Item(0). get_GridColumnStyles().Add(myColumn); } //CreateNewDataGridColumnStyle

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DataGridColumnStyle コンストラクタ

名前 | 説明 |
---|---|
DataGridColumnStyle () | 派生クラスで、DataGridColumnStyle クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |
DataGridColumnStyle (PropertyDescriptor) | PropertyDescriptor を指定して、DataGridColumnStyle クラスの新しいインスタンスを初期化します。 |

関連項目
DataGridColumnStyle クラスDataGridColumnStyle メンバ
System.Windows.Forms 名前空間
DataColumn
DataGrid クラス
DataGridColumnStyle プロパティ

名前 | 説明 | |
---|---|---|
![]() | Alignment | 列内のテキストの配置について値を取得または設定します。 |
![]() | Container | Component を格納している IContainer を取得します。 ( Component から継承されます。) |
![]() | Site | Component の ISite を取得または設定します。 ( Component から継承されます。) |
![]() | Width | 列の幅を取得または設定します。 |

名前 | 説明 | |
---|---|---|
![]() | CanRaiseEvents | コンポーネントがイベントを発生させることがきるかどうかを示す値を取得します。 ( Component から継承されます。) |
![]() | DesignMode | Component が現在デザイン モードかどうかを示す値を取得します。 ( Component から継承されます。) |
![]() | Events | Component に結び付けられているイベント ハンドラのリストを取得します。 ( Component から継承されます。) |
![]() | FontHeight | 列のフォントの高さを取得します。 |

関連項目
DataGridColumnStyle クラスSystem.Windows.Forms 名前空間
DataColumn
DataGrid クラス
DataGridBoolColumn クラス
DataGridTextBox
DataGridTableStyle
DataView
GridColumnStylesCollection
DataGridColumnStyle メソッド

名前 | 説明 | |
---|---|---|
![]() | CreateObjRef | リモート オブジェクトとの通信に使用するプロキシの生成に必要な情報をすべて格納しているオブジェクトを作成します。 ( MarshalByRefObject から継承されます。) |
![]() | Dispose | オーバーロードされます。 Component によって使用されているリソースを解放します。 ( Component から継承されます。) |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetLifetimeService | 対象のインスタンスの有効期間ポリシーを制御する、現在の有効期間サービス オブジェクトを取得します。 ( MarshalByRefObject から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | InitializeLifetimeService | 対象のインスタンスの有効期間ポリシーを制御する、有効期間サービス オブジェクトを取得します。 ( MarshalByRefObject から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ResetHeaderText | HeaderText を既定値 null 参照 (Visual Basic では Nothing) にリセットします。 |
![]() | ToString | Component の名前を格納している String を返します (存在する場合)。このメソッドはオーバーライドできません。 ( Component から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Abort | 派生クラスでオーバーライドされると、編集プロシージャを中断する要求を実行します。 |
![]() | BeginUpdate | EndUpdate メソッドが呼び出されるまで、列の描画を中断します。 |
![]() | CheckValidDataSource | System.Windows.Forms.DataGrid が有効なデータ ソースを保持していない場合、またはこの列がデータ ソースの有効なプロパティに割り当てられていない場合は、例外がスローされます。 |
![]() | ColumnStartedEditing | ユーザーが列の編集を開始したことを System.Windows.Forms.DataGrid に通知します。 |
![]() | Commit | 派生クラスでオーバーライドされると、編集プロシージャを完了する要求を実行します。 |
![]() | ConcedeFocus | 列がホストしているコントロールへのフォーカスを放棄する必要があることを列に通知します。 |
![]() | CreateHeaderAccessibleObject | 列の AccessibleObject を取得します。 |
![]() | Dispose | オーバーロードされます。 Component によって使用されているリソースを解放します。 ( Component から継承されます。) |
![]() | Edit | オーバーロードされます。 値を編集するためにセルを準備します。 |
![]() | EndUpdate | BeginUpdate メソッドを呼び出して中断されていた列の描画を再開します。 |
![]() | EnterNullValue | DBNull.Value を列に入力します。 |
![]() | Finalize | Component がガベージ コレクションによってクリアされる前に、アンマネージ リソースを解放し、その他のクリーンアップ操作を実行します。 ( Component から継承されます。) |
![]() | GetColumnValueAtRow | 指定した CurrencyManager から、指定した行の値を取得します。 |
![]() | GetMinimumHeight | 派生クラスでオーバーライドされると、行の最小の高さを取得します。 |
![]() | GetPreferredHeight | 派生クラスでオーバーライドされると、列のサイズを自動的に変更するために使用する高さを取得します。 |
![]() | GetPreferredSize | 派生クラスでオーバーライドされると、指定した値の幅および高さを取得します。この幅と高さは、ユーザーが DataGridColumnStyle を使用して DataGridTableStyle に移動するときに使用されます。 |
![]() | GetService | Component またはその Container で提供されるサービスを表すオブジェクトを返します。 ( Component から継承されます。) |
![]() | Invalidate | 列を再描画し、描画メッセージがコントロールに送信されます。 |
![]() | MemberwiseClone | オーバーロードされます。 ( MarshalByRefObject から継承されます。) |
![]() | Paint | オーバーロードされます。 派生クラスでオーバーライドされると、System.Windows.Forms.DataGrid コントロールの列を描画します。 |
![]() | ReleaseHostedControl | 列がホストするコントロールが不要な場合に、その列がリソースを解放できるようにします。 |
![]() | SetColumnValueAtRow | 指定した CurrencyManager からの値を使用して、指定した行の値を設定します。 |
![]() | SetDataGrid | この列が属する System.Windows.Forms.DataGrid コントロールを設定します。 |
![]() | SetDataGridInColumn | 列の System.Windows.Forms.DataGrid を設定します。 |
![]() | UpdateUI | 指定されたテキストを使用して、指定した行の値を更新します。 |

名前 | 説明 | |
---|---|---|
![]() | System.Windows.Forms.IDataGridColumnStyleEditingNotificationService.ColumnStartedEditing | ユーザーが列の編集を開始したことを DataGrid コントロールに通知します。 |

関連項目
DataGridColumnStyle クラスSystem.Windows.Forms 名前空間
DataColumn
DataGrid クラス
DataGridBoolColumn クラス
DataGridTextBox
DataGridTableStyle
DataView
GridColumnStylesCollection
DataGridColumnStyle メンバ
System.Windows.Forms.DataGrid コントロールの列に関する、外観、テキスト書式、および動作を指定します。このクラスは抽象クラスです。
DataGridColumnStyle データ型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() | Alignment | 列内のテキストの配置について値を取得または設定します。 |
![]() | Container | Component を格納している IContainer を取得します。(Component から継承されます。) |
![]() | Site | Component の ISite を取得または設定します。(Component から継承されます。) |
![]() | Width | 列の幅を取得または設定します。 |

名前 | 説明 | |
---|---|---|
![]() | CanRaiseEvents | コンポーネントがイベントを発生させることがきるかどうかを示す値を取得します。(Component から継承されます。) |
![]() | DesignMode | Component が現在デザイン モードかどうかを示す値を取得します。(Component から継承されます。) |
![]() | Events | Component に結び付けられているイベント ハンドラのリストを取得します。(Component から継承されます。) |
![]() | FontHeight | 列のフォントの高さを取得します。 |

名前 | 説明 | |
---|---|---|
![]() | CreateObjRef | リモート オブジェクトとの通信に使用するプロキシの生成に必要な情報をすべて格納しているオブジェクトを作成します。 (MarshalByRefObject から継承されます。) |
![]() | Dispose | オーバーロードされます。 Component によって使用されているリソースを解放します。 (Component から継承されます。) |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetLifetimeService | 対象のインスタンスの有効期間ポリシーを制御する、現在の有効期間サービス オブジェクトを取得します。 (MarshalByRefObject から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | InitializeLifetimeService | 対象のインスタンスの有効期間ポリシーを制御する、有効期間サービス オブジェクトを取得します。 (MarshalByRefObject から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ResetHeaderText | HeaderText を既定値 null 参照 (Visual Basic では Nothing) にリセットします。 |
![]() | ToString | Component の名前を格納している String を返します (存在する場合)。このメソッドはオーバーライドできません。 (Component から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Abort | 派生クラスでオーバーライドされると、編集プロシージャを中断する要求を実行します。 |
![]() | BeginUpdate | EndUpdate メソッドが呼び出されるまで、列の描画を中断します。 |
![]() | CheckValidDataSource | System.Windows.Forms.DataGrid が有効なデータ ソースを保持していない場合、またはこの列がデータ ソースの有効なプロパティに割り当てられていない場合は、例外がスローされます。 |
![]() | ColumnStartedEditing | ユーザーが列の編集を開始したことを System.Windows.Forms.DataGrid に通知します。 |
![]() | Commit | 派生クラスでオーバーライドされると、編集プロシージャを完了する要求を実行します。 |
![]() | ConcedeFocus | 列がホストしているコントロールへのフォーカスを放棄する必要があることを列に通知します。 |
![]() | CreateHeaderAccessibleObject | 列の AccessibleObject を取得します。 |
![]() | Dispose | オーバーロードされます。 Component によって使用されているリソースを解放します。 (Component から継承されます。) |
![]() | Edit | オーバーロードされます。 値を編集するためにセルを準備します。 |
![]() | EndUpdate | BeginUpdate メソッドを呼び出して中断されていた列の描画を再開します。 |
![]() | EnterNullValue | DBNull.Value を列に入力します。 |
![]() | Finalize | Component がガベージ コレクションによってクリアされる前に、アンマネージ リソースを解放し、その他のクリーンアップ操作を実行します。 (Component から継承されます。) |
![]() | GetColumnValueAtRow | 指定した CurrencyManager から、指定した行の値を取得します。 |
![]() | GetMinimumHeight | 派生クラスでオーバーライドされると、行の最小の高さを取得します。 |
![]() | GetPreferredHeight | 派生クラスでオーバーライドされると、列のサイズを自動的に変更するために使用する高さを取得します。 |
![]() | GetPreferredSize | 派生クラスでオーバーライドされると、指定した値の幅および高さを取得します。この幅と高さは、ユーザーが DataGridColumnStyle を使用して DataGridTableStyle に移動するときに使用されます。 |
![]() | GetService | Component またはその Container で提供されるサービスを表すオブジェクトを返します。 (Component から継承されます。) |
![]() | Invalidate | 列を再描画し、描画メッセージがコントロールに送信されます。 |
![]() | MemberwiseClone | オーバーロードされます。 ( MarshalByRefObject から継承されます。) |
![]() | Paint | オーバーロードされます。 派生クラスでオーバーライドされると、System.Windows.Forms.DataGrid コントロールの列を描画します。 |
![]() | ReleaseHostedControl | 列がホストするコントロールが不要な場合に、その列がリソースを解放できるようにします。 |
![]() | SetColumnValueAtRow | 指定した CurrencyManager からの値を使用して、指定した行の値を設定します。 |
![]() | SetDataGrid | この列が属する System.Windows.Forms.DataGrid コントロールを設定します。 |
![]() | SetDataGridInColumn | 列の System.Windows.Forms.DataGrid を設定します。 |
![]() | UpdateUI | 指定されたテキストを使用して、指定した行の値を更新します。 |

名前 | 説明 | |
---|---|---|
![]() | Disposed | コンポーネントの Disposed イベントを待機するイベント ハンドラを追加します。(Component から継承されます。) |
![]() | FontChanged | 列のフォントが変更されたときに発生します。 |
![]() | HeaderTextChanged | HeaderText プロパティの値が変更された場合に発生します。 |
![]() | MappingNameChanged | MappingName の値が変更された場合に発生します。 |
![]() | NullTextChanged | NullText の値が変更された場合に発生します。 |
![]() | PropertyDescriptorChanged | PropertyDescriptor プロパティの値が変更された場合に発生します。 |
![]() | ReadOnlyChanged | ReadOnly プロパティの値が変更された場合に発生します。 |
![]() | WidthChanged | Width プロパティの値が変更された場合に発生します。 |

名前 | 説明 | |
---|---|---|
![]() | System.Windows.Forms.IDataGridColumnStyleEditingNotificationService.ColumnStartedEditing | ユーザーが列の編集を開始したことを DataGrid コントロールに通知します。 |

関連項目
DataGridColumnStyle クラスSystem.Windows.Forms 名前空間
DataColumn
DataGrid クラス
DataGridBoolColumn クラス
DataGridTextBox
DataGridTableStyle
DataView
GridColumnStylesCollection
- DataGridColumnStyleのページへのリンク