DataGridBoolColumn Class
Specifies a column in which each cell contains a check box for representing a Boolean value.
System::MarshalByRefObject
System.ComponentModel::Component
System.Windows.Forms::DataGridColumnStyle
System.Windows.Forms::DataGridBoolColumn
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
The DataGridBoolColumn type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | DataGridBoolColumn() | Initializes a new instance of the DataGridBoolColumn class. |
![]() | DataGridBoolColumn(PropertyDescriptor) | Initializes a new instance of a DataGridBoolColumn with the specified PropertyDescriptor. |
![]() | DataGridBoolColumn(PropertyDescriptor, Boolean) | Initializes a new instance of a DataGridBoolColumn with the specified PropertyDescriptor, and specifying whether the column style is a default column. |
| Name | Description | |
|---|---|---|
![]() | Alignment | Gets or sets the alignment of text in a column. (Inherited from DataGridColumnStyle.) |
![]() | AllowNull | Gets or sets a value indicating whether null values are allowed. |
![]() | CanRaiseEvents | Gets a value indicating whether the component can raise an event. (Inherited from Component.) |
![]() | Container | Gets the IContainer that contains the Component. (Inherited from Component.) |
![]() | DataGridTableStyle | Gets the DataGridTableStyle for the column. (Inherited from DataGridColumnStyle.) |
![]() | DesignMode | Gets a value that indicates whether the Component is currently in design mode. (Inherited from Component.) |
![]() | Events | Gets the list of event handlers that are attached to this Component. (Inherited from Component.) |
![]() | FalseValue | Gets or sets the actual value used when setting the value of the column to false. |
![]() | FontHeight | Gets the height of the column's font. (Inherited from DataGridColumnStyle.) |
![]() | HeaderAccessibleObject | Infrastructure. Gets the AccessibleObject for the column. (Inherited from DataGridColumnStyle.) |
![]() | HeaderText | Gets or sets the text of the column header. (Inherited from DataGridColumnStyle.) |
![]() | MappingName | Gets or sets the name of the data member to map the column style to. (Inherited from DataGridColumnStyle.) |
![]() | NullText | Gets or sets the text that is displayed when the column contains nullptr. (Inherited from DataGridColumnStyle.) |
![]() | NullValue | Gets or sets the actual value used when setting the value of the column to Value. |
![]() | PropertyDescriptor | Gets or sets the PropertyDescriptor that determines the attributes of data displayed by the DataGridColumnStyle. (Inherited from DataGridColumnStyle.) |
![]() | ReadOnly | Gets or sets a value indicating whether the data in the column can be edited. (Inherited from DataGridColumnStyle.) |
![]() | Site | Gets or sets the ISite of the Component. (Inherited from Component.) |
![]() | TrueValue | Gets or sets the actual value used when setting the value of the column to true. |
![]() | Width | Gets or sets the width of the column. (Inherited from DataGridColumnStyle.) |
| Name | Description | |
|---|---|---|
![]() | Abort | Initiates a request to interrupt an edit procedure. (Overrides DataGridColumnStyle::Abort(Int32).) |
![]() | BeginUpdate | Suspends the painting of the column until the EndUpdate method is called. (Inherited from DataGridColumnStyle.) |
![]() | CheckValidDataSource | Throws an exception if the System.Windows.Forms::DataGrid does not have a valid data source, or if this column is not mapped to a valid property in the data source. (Inherited from DataGridColumnStyle.) |
![]() | ColumnStartedEditing | Informs the System.Windows.Forms::DataGrid that the user has begun editing the column. (Inherited from DataGridColumnStyle.) |
![]() | Commit | Initiates a request to complete an editing procedure. (Overrides DataGridColumnStyle::Commit(CurrencyManager, Int32).) |
![]() | ConcedeFocus | Notifies a column that it must relinquish the focus to the control it is hosting. (Overrides DataGridColumnStyle::ConcedeFocus().) |
![]() | CreateHeaderAccessibleObject | Gets the AccessibleObject for the column. (Inherited from DataGridColumnStyle.) |
![]() | CreateObjRef | Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.) |
![]() | Dispose() | Releases all resources used by the Component. (Inherited from Component.) |
![]() | Dispose(Boolean) | Releases the unmanaged resources used by the Component and optionally releases the managed resources. (Inherited from Component.) |
![]() | Edit(CurrencyManager, Int32, Rectangle, Boolean) | Prepares a cell for editing. (Inherited from DataGridColumnStyle.) |
![]() | Edit(CurrencyManager, Int32, Rectangle, Boolean, String) | Prepares the cell for editing using the specified CurrencyManager, row number, and Rectangle parameters. (Inherited from DataGridColumnStyle.) |
![]() | Edit(CurrencyManager, Int32, Rectangle, Boolean, String, Boolean) | Prepares the cell for editing a value. (Overrides DataGridColumnStyle::Edit(CurrencyManager, Int32, Rectangle, Boolean, String, Boolean).) |
![]() | EndUpdate | Resumes the painting of columns suspended by calling the BeginUpdate method. (Inherited from DataGridColumnStyle.) |
![]() | EnterNullValue | Enters a Value into the column. (Overrides DataGridColumnStyle::EnterNullValue().) |
![]() | Equals(Object) | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) |
![]() | Finalize | Releases unmanaged resources and performs other cleanup operations before the Component is reclaimed by garbage collection. (Inherited from Component.) |
![]() | GetColumnValueAtRow | Gets the value at the specified row. (Overrides DataGridColumnStyle::GetColumnValueAtRow(CurrencyManager, Int32).) |
![]() | GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) |
![]() | GetLifetimeService | Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.) |
![]() | GetMinimumHeight | Gets the height of a cell in a column. (Overrides DataGridColumnStyle::GetMinimumHeight().) |
![]() | GetPreferredHeight | Gets the height used when resizing columns. (Overrides DataGridColumnStyle::GetPreferredHeight(Graphics, Object).) |
![]() | GetPreferredSize | Gets the optimum width and height of a cell given a specific value to contain. (Overrides DataGridColumnStyle::GetPreferredSize(Graphics, Object).) |
![]() | GetService | Returns an object that represents a service provided by the Component or by its Container. (Inherited from Component.) |
![]() | GetType | Gets the Type of the current instance. (Inherited from Object.) |
![]() | InitializeLifetimeService | Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.) |
![]() | Invalidate | Redraws the column and causes a paint message to be sent to the control. (Inherited from DataGridColumnStyle.) |
![]() | MemberwiseClone() | Creates a shallow copy of the current Object. (Inherited from Object.) |
![]() | MemberwiseClone(Boolean) | Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.) |
![]() | Paint(Graphics, Rectangle, CurrencyManager, Int32) | Infrastructure. Draws the DataGridBoolColumn with the given Graphics, Rectangle and row number. (Overrides DataGridColumnStyle::Paint(Graphics, Rectangle, CurrencyManager, Int32).) |
![]() | Paint(Graphics, Rectangle, CurrencyManager, Int32, Boolean) | Infrastructure. Draws the DataGridBoolColumn with the given Graphics, Rectangle, row number, and alignment settings. (Overrides DataGridColumnStyle::Paint(Graphics, Rectangle, CurrencyManager, Int32, Boolean).) |
![]() | Paint(Graphics, Rectangle, CurrencyManager, Int32, Brush, Brush, Boolean) | Draws the DataGridBoolColumn with the given Graphics, Rectangle, row number, Brush, and Color. (Overrides DataGridColumnStyle::Paint(Graphics, Rectangle, CurrencyManager, Int32, Brush, Brush, Boolean).) |
![]() | ReleaseHostedControl | Allows the column to free resources when the control it hosts is not needed. (Inherited from DataGridColumnStyle.) |
![]() | ResetHeaderText | Resets the HeaderText to its default value, nullptr. (Inherited from DataGridColumnStyle.) |
![]() | SetColumnValueAtRow | Sets the value of a specified row. (Overrides DataGridColumnStyle::SetColumnValueAtRow(CurrencyManager, Int32, Object).) |
![]() | SetDataGrid | Sets the System.Windows.Forms::DataGrid control that this column belongs to. (Inherited from DataGridColumnStyle.) |
![]() | SetDataGridInColumn | Sets the System.Windows.Forms::DataGrid for the column. (Inherited from DataGridColumnStyle.) |
![]() | ToString | Returns a String containing the name of the Component, if any. This method should not be overridden. (Inherited from Component.) |
![]() | UpdateUI | Updates the value of a specified row with the given text. (Inherited from DataGridColumnStyle.) |
| Name | Description | |
|---|---|---|
![]() | AlignmentChanged | Occurs when the Alignment property value changes. (Inherited from DataGridColumnStyle.) |
![]() | AllowNullChanged | Occurs when the AllowNull property is changed. |
![]() | Disposed | Occurs when the component is disposed by a call to the Dispose method. (Inherited from Component.) |
![]() | FalseValueChanged | Occurs when the FalseValue property is changed. |
![]() | FontChanged | Occurs when the column's font changes. (Inherited from DataGridColumnStyle.) |
![]() | HeaderTextChanged | Occurs when the HeaderText property value changes. (Inherited from DataGridColumnStyle.) |
![]() | MappingNameChanged | Occurs when the MappingName value changes. (Inherited from DataGridColumnStyle.) |
![]() | NullTextChanged | Occurs when the NullText value changes. (Inherited from DataGridColumnStyle.) |
![]() | PropertyDescriptorChanged | Occurs when the PropertyDescriptor property value changes. (Inherited from DataGridColumnStyle.) |
![]() | ReadOnlyChanged | Occurs when the ReadOnly property value changes. (Inherited from DataGridColumnStyle.) |
![]() | TrueValueChanged | Occurs when the TrueValue property value is changed. |
![]() | WidthChanged | Occurs when the Width property value changes. (Inherited from DataGridColumnStyle.) |
| Name | Description | |
|---|---|---|
![]() ![]() | IDataGridColumnStyleEditingNotificationService::ColumnStartedEditing | Informs the DataGrid control that the user has begun editing the column. (Inherited from DataGridColumnStyle.) |
The DataGridBoolColumn derives from the abstract class DataGridColumnStyle. At run time, the DataGridBoolColumn contains check boxes in each cell that have three states by default: checked (true), unchecked (false), and Value. To use two-state check boxes, set the AllowNull property to false.
Properties added to the class include FalseValue, NullValue, and TrueValue. These properties specify the value underlying each of the column's states.
The following code example first creates a new DataGridBoolColumn and adds it to the GridColumnStylesCollection of a DataGridTableStyle.
using namespace System; using namespace System::Data; using namespace System::Windows::Forms; using namespace System::Drawing; using namespace System::ComponentModel; public ref class DataGridBoolColumnInherit: public DataGridBoolColumn { private: SolidBrush^ trueBrush; SolidBrush^ falseBrush; DataColumn^ expressionColumn; static int count = 0; public: DataGridBoolColumnInherit() : DataGridBoolColumn() { trueBrush = dynamic_cast<SolidBrush^>(Brushes::Blue); falseBrush = dynamic_cast<SolidBrush^>(Brushes::Yellow); expressionColumn = nullptr; count++; } property Color FalseColor { Color get() { return falseBrush->Color; } void set( Color value ) { falseBrush = gcnew System::Drawing::SolidBrush( value ); Invalidate(); } } property Color TrueColor { Color get() { return trueBrush->Color; } void set( Color value ) { trueBrush = gcnew System::Drawing::SolidBrush( value ); Invalidate(); } } property String^ Expression { // This will work only with a DataSet or DataTable. // The code is not compatible with IBindingList* implementations. String^ get() { return this->expressionColumn == nullptr ? String::Empty : this->expressionColumn->Expression; } void set( String^ value ) { if ( expressionColumn == nullptr ) AddExpressionColumn( value ); else expressionColumn->Expression = value; if ( expressionColumn != nullptr && expressionColumn->Expression->Equals( value ) ) return; Invalidate(); } } private: void AddExpressionColumn( String^ value ) { // Get the grid's data source. First check for a 0 // table or data grid. if ( this->DataGridTableStyle == nullptr || this->DataGridTableStyle->DataGrid == nullptr ) return; DataGrid^ myGrid = this->DataGridTableStyle->DataGrid; DataView^ myDataView = dynamic_cast<DataView^>((dynamic_cast<CurrencyManager^>(myGrid->BindingContext[ myGrid->DataSource,myGrid->DataMember ]))->List); // This works only with System::Data::DataTable. if ( myDataView == nullptr ) return; // If the user already added a column with the name // then exit. Otherwise, add the column and set the // expression to the value passed to this function. DataColumn^ col = myDataView->Table->Columns[ "__Computed__Column__" ]; if ( col != nullptr ) return; col = gcnew DataColumn( String::Concat( "__Computed__Column__", count ) ); myDataView->Table->Columns->Add( col ); col->Expression = value; expressionColumn = col; } // the OnPaint method to paint the cell based on the expression. protected: virtual void Paint( Graphics^ g, Rectangle bounds, CurrencyManager^ source, int rowNum, Brush^ backBrush, Brush^ foreBrush, bool alignToRight ) override { bool trueExpression = false; bool hasExpression = false; DataRowView^ drv = dynamic_cast<DataRowView^>(source->List[ rowNum ]); hasExpression = this->expressionColumn != nullptr && this->expressionColumn->Expression != nullptr && !this->expressionColumn->Expression->Equals( String::Empty ); Console::WriteLine( String::Format( "hasExpressionValue {0}", hasExpression ) ); // Get the value from the expression column. // For simplicity, we assume a True/False value for the // expression column. if ( hasExpression ) { Object^ expr = drv->Row[ expressionColumn->ColumnName ]; trueExpression = expr->Equals( "True" ); } // Let the DataGridBoolColumn do the painting. if ( !hasExpression ) DataGridBoolColumn::Paint( g, bounds, source, rowNum, backBrush, foreBrush, alignToRight ); // Paint using the expression color for true or false, as calculated. if ( trueExpression ) DataGridBoolColumn::Paint( g, bounds, source, rowNum, trueBrush, foreBrush, alignToRight ); else DataGridBoolColumn::Paint( g, bounds, source, rowNum, falseBrush, foreBrush, alignToRight ); } }; public ref class MyForm: public Form { private: DataTable^ myTable; DataGrid^ myGrid; public: MyForm() { myGrid = gcnew DataGrid; try { InitializeComponent(); myTable = gcnew DataTable( "NamesTable" ); myTable->Columns->Add( gcnew DataColumn( "Name" ) ); DataColumn^ column = gcnew DataColumn( "id",Int32::typeid ); myTable->Columns->Add( column ); myTable->Columns->Add( gcnew DataColumn( "calculatedField",bool::typeid ) ); DataSet^ namesDataSet = gcnew DataSet; namesDataSet->Tables->Add( myTable ); myGrid->SetDataBinding( namesDataSet, "NamesTable" ); AddTableStyle(); AddData(); } catch ( System::Exception^ exc ) { Console::WriteLine( exc ); } } private: void grid_Enter( Object^ sender, EventArgs^ e ) { myGrid->CurrentCell = DataGridCell(2,2); } void AddTableStyle() { // Map a new TableStyle to the DataTable. Then // add DataGridColumnStyle objects to the collection // of column styles with appropriate mappings. DataGridTableStyle^ dgt = gcnew DataGridTableStyle; dgt->MappingName = "NamesTable"; DataGridTextBoxColumn^ dgtbc = gcnew DataGridTextBoxColumn; dgtbc->MappingName = "Name"; dgtbc->HeaderText = "Name"; dgt->GridColumnStyles->Add( dgtbc ); dgtbc = gcnew DataGridTextBoxColumn; dgtbc->MappingName = "id"; dgtbc->HeaderText = "id"; dgt->GridColumnStyles->Add( dgtbc ); DataGridBoolColumnInherit^ db = gcnew DataGridBoolColumnInherit; db->HeaderText = "less than 1000 = blue"; db->Width = 150; db->MappingName = "calculatedField"; dgt->GridColumnStyles->Add( db ); myGrid->TableStyles->Add( dgt ); // This expression instructs the grid to change // the color of the inherited DataGridBoolColumn // according to the value of the id field. If it's // less than 1000, the row is blue. Otherwise, // the color is yellow. db->Expression = "id < 1000"; } void AddData() { // Add data with varying numbers for the id field. // If the number is over 1000, the cell will paint // yellow. Otherwise, it will be blue. DataRow^ dRow = myTable->NewRow(); dRow[ "Name" ] = "name 1 "; dRow[ "id" ] = 999; myTable->Rows->Add( dRow ); dRow = myTable->NewRow(); dRow[ "Name" ] = "name 2"; dRow[ "id" ] = 2300; myTable->Rows->Add( dRow ); dRow = myTable->NewRow(); dRow[ "Name" ] = "name 3"; dRow[ "id" ] = 120; myTable->Rows->Add( dRow ); dRow = myTable->NewRow(); dRow[ "Name" ] = "name 4"; dRow[ "id" ] = 4023; myTable->Rows->Add( dRow ); dRow = myTable->NewRow(); dRow[ "Name" ] = "name 5"; dRow[ "id" ] = 2345; myTable->Rows->Add( dRow ); myTable->AcceptChanges(); } void InitializeComponent() { this->Size = System::Drawing::Size( 500, 500 ); myGrid->Size = System::Drawing::Size( 350, 250 ); myGrid->TabStop = true; myGrid->TabIndex = 1; this->StartPosition = FormStartPosition::CenterScreen; this->Controls->Add( myGrid ); } }; [STAThread] int main() { Application::Run( gcnew MyForm ); }
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
