DataGridBoolColumn DataGridBoolColumn DataGridBoolColumn DataGridBoolColumn Class

定义

指定一列,该列中每个单元格均包含一个表示布尔值的复选框。Specifies a column in which each cell contains a check box for representing a Boolean value.

public ref class DataGridBoolColumn : System::Windows::Forms::DataGridColumnStyle
public class DataGridBoolColumn : System.Windows.Forms.DataGridColumnStyle
type DataGridBoolColumn = class
    inherit DataGridColumnStyle
Public Class DataGridBoolColumn
Inherits DataGridColumnStyle
继承

示例

下面的代码示例首先创建一个新DataGridBoolColumn并将其添加到GridColumnStylesCollectionDataGridTableStyleThe 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 );
}
using System;
using System.Data;
using System.Windows.Forms;
using System.Drawing;
using System.ComponentModel;

public class MyForm : Form 
{
    private DataTable myTable;
    private DataGrid myGrid = new DataGrid();
    
    public MyForm() : base() 
    {
        try
        {
            InitializeComponent();

            myTable = new DataTable("NamesTable");
            myTable.Columns.Add(new DataColumn("Name"));
            DataColumn column = new DataColumn
                ("id", typeof(System.Int32));
            myTable.Columns.Add(column);
            myTable.Columns.Add(new 
                DataColumn("calculatedField", typeof(bool)));
            DataSet namesDataSet = new DataSet();
            namesDataSet.Tables.Add(myTable);
            myGrid.SetDataBinding(namesDataSet, "NamesTable");
        
            AddTableStyle();
            AddData();
        }
        catch (System.Exception exc)
        {
            Console.WriteLine(exc.ToString());
        }
    }

    
    private void grid_Enter(object sender, EventArgs e) 
    {
        myGrid.CurrentCell = new DataGridCell(2,2);
    }

    private void AddTableStyle()
    {
        // Map a new  TableStyle to the DataTable. Then 
        // add DataGridColumnStyle objects to the collection
        // of column styles with appropriate mappings.
        DataGridTableStyle dgt = new DataGridTableStyle();
        dgt.MappingName = "NamesTable";

        DataGridTextBoxColumn dgtbc = new DataGridTextBoxColumn();
        dgtbc.MappingName = "Name";
        dgtbc.HeaderText= "Name";
        dgt.GridColumnStyles.Add(dgtbc);

        dgtbc = new DataGridTextBoxColumn();
        dgtbc.MappingName = "id";
        dgtbc.HeaderText= "id";
        dgt.GridColumnStyles.Add(dgtbc);

        DataGridBoolColumnInherit db = 
            new 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";
    }

    private 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();
    }

    private void InitializeComponent() 
    {
        this.Size = new Size(500, 500);
        myGrid.Size = new Size(350, 250);
        myGrid.TabStop = true;
        myGrid.TabIndex = 1;
      
        this.StartPosition = FormStartPosition.CenterScreen;
        this.Controls.Add(myGrid);
      }
    [STAThread]
    public static void Main() 
    {
        Application.Run(new MyForm());
    }
}

public class DataGridBoolColumnInherit : DataGridBoolColumn 
{
    private SolidBrush trueBrush = Brushes.Blue as SolidBrush;
    private SolidBrush falseBrush = Brushes.Yellow as SolidBrush;
    private DataColumn expressionColumn = null;
    private static int count = 0;

    public Color FalseColor 
    {
        get 
        {
            return falseBrush.Color;
        }
        set 
        {
            falseBrush = new SolidBrush(value);
            Invalidate();
        }
    }

    public Color TrueColor 
    {
        get 
        {
            return trueBrush.Color;
        }
        set 
        {
            trueBrush = new SolidBrush(value);
            Invalidate();
        }
    }

    public DataGridBoolColumnInherit() : base () 
    {
        count ++;
    }


    // This will work only with a DataSet or DataTable.
    // The code is not compatible with IBindingList implementations.
    public string Expression 
    {
        get 
        {
            return this.expressionColumn == null ? String.Empty : 
                this.expressionColumn.Expression;
        }
        set 
        {
            if (expressionColumn == null)
                AddExpressionColumn(value);
            else 
                expressionColumn.Expression = value;
            if (expressionColumn != null && 
                expressionColumn.Expression.Equals(value))
                return;
            Invalidate();
        }
    }

    private void AddExpressionColumn(string value) 
    {
        // Get the grid's data source. First check for a null 
        // table or data grid.
        if (this.DataGridTableStyle == null || 
            this.DataGridTableStyle.DataGrid == null)
            return;

        DataGrid myGrid = this.DataGridTableStyle.DataGrid;
        DataView myDataView = ((CurrencyManager) 
            myGrid.BindingContext[myGrid.DataSource, 
            myGrid.DataMember]).List 
            as DataView;

        // This works only with System.Data.DataTable.
        if (myDataView == null)
            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 != null)
            return;
        col = new DataColumn("__Computed__Column__" + count.ToString());

        myDataView.Table.Columns.Add(col);
        col.Expression = value;
        expressionColumn = col;
    }

    // override the OnPaint method to paint the cell based on the expression.
    protected override void Paint(Graphics g, Rectangle bounds,
        CurrencyManager source, int rowNum,
        Brush backBrush, Brush foreBrush,
        bool alignToRight) 
    {
        bool trueExpression = false;
        bool hasExpression = false;
        DataRowView drv = source.List[rowNum] as DataRowView;

        hasExpression = this.expressionColumn != null && 
            this.expressionColumn.Expression != null && 
            !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)
            base.Paint(g, bounds, source, rowNum, 
                backBrush, foreBrush, alignToRight);

        // Paint using the expression color for true or false, as calculated.
        if (trueExpression)
            base.Paint(g, bounds, source, rowNum, 
                trueBrush, foreBrush, alignToRight);
        else
            base.Paint(g, bounds, source, rowNum, 
                falseBrush, foreBrush, alignToRight);
    }
}
Imports System
Imports System.Data
Imports System.Windows.Forms
Imports System.Drawing
Imports System.ComponentModel

Public Class MyForm
    Inherits System.Windows.Forms.Form
    Private components As System.ComponentModel.Container
    Private myTable As DataTable
    Private myGrid As DataGrid = New DataGrid()

    Public Shared Sub Main()
        Application.Run(New MyForm())
    End Sub

    Public Sub New()
        Try
            InitializeComponent()
            myTable = New DataTable("NamesTable")
            myTable.Columns.Add(New DataColumn("Name"))
            Dim column As DataColumn = New DataColumn _
            ("id", GetType(System.Int32))
            myTable.Columns.Add(column)
            myTable.Columns.Add(New DataColumn _
            ("calculatedField", GetType(Boolean)))
            Dim namesDataSet As DataSet = New DataSet("myDataSet")
            namesDataSet.Tables.Add(myTable)
            myGrid.SetDataBinding(namesDataSet, "NamesTable")
            AddData()
            AddTableStyle()

        Catch exc As System.Exception
            Console.WriteLine(exc.ToString)
        End Try
    End Sub

    Private Sub AddTableStyle()
        ' Map a new  TableStyle to the DataTable. Then 
        ' add DataGridColumnStyle objects to the collection
        ' of column styles with appropriate mappings.
        Dim dgt As DataGridTableStyle = New DataGridTableStyle()
        dgt.MappingName = "NamesTable"

        Dim dgtbc As DataGridTextBoxColumn = _
        New DataGridTextBoxColumn()
        dgtbc.MappingName = "Name"
        dgtbc.HeaderText = "Name"
        dgt.GridColumnStyles.Add(dgtbc)

        dgtbc = New DataGridTextBoxColumn()
        dgtbc.MappingName = "id"
        dgtbc.HeaderText = "id"
        dgt.GridColumnStyles.Add(dgtbc)

        Dim db As DataGridBoolColumnInherit = _
        New 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"
    End Sub

    Private Sub 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.
        Dim dRow As 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()
    End Sub

    Private Sub InitializeComponent()
        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

End Class


Public Class DataGridBoolColumnInherit
    Inherits DataGridBoolColumn

    Private trueBrush As SolidBrush = Brushes.Blue
    Private falseBrush As SolidBrush = Brushes.Yellow
    Private expressionColumn As DataColumn = Nothing
    Shared count As Int32 = 0

    Public Property FalseColor() As Color
        Get
            Return falseBrush.Color
        End Get

        Set(ByVal Value As Color)

            falseBrush = New SolidBrush(Value)
            Invalidate()
        End Set
    End Property

    Public Property TrueColor() As Color
        Get
            Return trueBrush.Color
        End Get

        Set(ByVal Value As Color)

            trueBrush = New SolidBrush(Value)
            Invalidate()
        End Set
    End Property

    Public Sub New()
        count += 1
    End Sub

    ' This will work only with a DataSet or DataTable.
    ' The code is not compatible with IBindingList implementations.
    Public Property Expression() As String
        Get
            If Me.expressionColumn Is Nothing Then
                Return String.Empty
            Else
                Return Me.expressionColumn.Expression
            End If
        End Get
        Set(ByVal Value As String)
            If expressionColumn Is Nothing Then
                AddExpressionColumn(Value)
            Else
                expressionColumn.Expression = Value
            End If
            If (expressionColumn IsNot Nothing) And expressionColumn.Expression.Equals(Value) Then
                Return
            End If
            Invalidate()
        End Set
    End Property

    Private Sub AddExpressionColumn(ByVal value As String)
        ' Get the grid's data source. First check for a null 
        ' table or data grid.
        If Me.DataGridTableStyle Is Nothing Or _
        Me.DataGridTableStyle.DataGrid Is Nothing Then
            Return
        End If

        Dim dg As DataGrid = Me.DataGridTableStyle.DataGrid
        Dim dv As DataView = CType(dg.BindingContext(dg.DataSource, dg.DataMember), CurrencyManager).List

        ' This works only with System.Data.DataTable.
        If dv Is Nothing Then
            Return
        End If

        ' 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.
        Dim col As DataColumn = dv.Table.Columns("__Computed__Column__")
        If (col IsNot Nothing) Then
            Return
        End If
        col = New DataColumn("__Computed__Column__" + count.ToString())

        dv.Table.Columns.Add(col)

        col.Expression = value
        expressionColumn = col
    End Sub


    ' Override the OnPaint method to paint the cell based on the expression.
    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 trueExpression As Boolean = False
        Dim hasExpression As Boolean = False
        Dim drv As DataRowView = [source].List(rowNum)
        hasExpression = (Me.expressionColumn IsNot Nothing) And (Me.expressionColumn.Expression IsNot Nothing) And Not Me.expressionColumn.Expression.Equals([String].Empty)

        ' Get the value from the expression column.
        ' For simplicity, we assume a True/False value for the 
        ' expression column.
        If hasExpression Then
            Dim expr As Object = drv.Row(expressionColumn.ColumnName)
            trueExpression = expr.Equals("True")
        End If

        ' Let the DataGridBoolColumn do the painting.
        If Not hasExpression Then
            MyBase.Paint(g, bounds, [source], rowNum, backBrush, foreBrush, alignToRight)
        End If

        ' Paint using the expression color for true or false, as calculated.
        If trueExpression Then
            MyBase.Paint(g, bounds, [source], rowNum, trueBrush, foreBrush, alignToRight)
        Else
            MyBase.Paint(g, bounds, [source], rowNum, falseBrush, foreBrush, alignToRight)
        End If
    End Sub
End Class

注解

DataGridBoolColumn派生自abstractDataGridColumnStyleThe DataGridBoolColumn derives from the abstract class DataGridColumnStyle. 在运行时,DataGridBoolColumn包含每个单元格中的复选框,默认情况下有三种状态: 检查 (true)、 未选中状态 (false),和ValueAt run time, the DataGridBoolColumn contains check boxes in each cell that have three states by default: checked (true), unchecked (false), and Value. 若要使用两个状态的复选框,将AllowNull属性设置为falseTo use two-state check boxes, set the AllowNull property to false.

添加到类属性包括FalseValueNullValue,和TrueValueProperties added to the class include FalseValue, NullValue, and TrueValue. 这些属性指定基础每一列的状态的值。These properties specify the value underlying each of the column's states.

构造函数

DataGridBoolColumn() DataGridBoolColumn() DataGridBoolColumn() DataGridBoolColumn()

初始化 DataGridBoolColumn 类的新实例。Initializes a new instance of the DataGridBoolColumn class.

DataGridBoolColumn(PropertyDescriptor) DataGridBoolColumn(PropertyDescriptor) DataGridBoolColumn(PropertyDescriptor) DataGridBoolColumn(PropertyDescriptor)

用指定的 DataGridBoolColumn 初始化 PropertyDescriptor 的一个新实例。Initializes a new instance of a DataGridBoolColumn with the specified PropertyDescriptor.

DataGridBoolColumn(PropertyDescriptor, Boolean) DataGridBoolColumn(PropertyDescriptor, Boolean) DataGridBoolColumn(PropertyDescriptor, Boolean) DataGridBoolColumn(PropertyDescriptor, Boolean)

使用指定的 DataGridBoolColumnPropertyDescriptor 的新实例进行初始化,并指定列样式是否为默认列。Initializes a new instance of a DataGridBoolColumn with the specified PropertyDescriptor, and specifying whether the column style is a default column.

属性

Alignment Alignment Alignment Alignment

获取或设置列中文本的对齐方式。Gets or sets the alignment of text in a column.

(Inherited from DataGridColumnStyle)
AllowNull AllowNull AllowNull AllowNull

获取或设置一个值,该值指示是否允许空值。Gets or sets a value indicating whether null values are allowed.

CanRaiseEvents CanRaiseEvents CanRaiseEvents CanRaiseEvents

获取一个指示组件是否可以引发事件的值。Gets a value indicating whether the component can raise an event.

(Inherited from Component)
Container Container Container Container

获取 IContainer,它包含 ComponentGets the IContainer that contains the Component.

(Inherited from Component)
DataGridTableStyle DataGridTableStyle DataGridTableStyle DataGridTableStyle

获取列的 DataGridTableStyleGets the DataGridTableStyle for the column.

(Inherited from DataGridColumnStyle)
DesignMode DesignMode DesignMode DesignMode

获取一个值,用以指示 Component 当前是否处于设计模式。Gets a value that indicates whether the Component is currently in design mode.

(Inherited from Component)
Events Events Events Events

获取附加到此 Component 的事件处理程序的列表。Gets the list of event handlers that are attached to this Component.

(Inherited from Component)
FalseValue FalseValue FalseValue FalseValue

获取或设置在将列值设置为 false 时使用的实际值。Gets or sets the actual value used when setting the value of the column to false.

FontHeight FontHeight FontHeight FontHeight

获取该列字体的高度。Gets the height of the column's font.

(Inherited from DataGridColumnStyle)
HeaderAccessibleObject HeaderAccessibleObject HeaderAccessibleObject HeaderAccessibleObject

获取列的 AccessibleObjectGets the AccessibleObject for the column.

(Inherited from DataGridColumnStyle)
HeaderText HeaderText HeaderText HeaderText

获取或设置列标题的文本。Gets or sets the text of the column header.

(Inherited from DataGridColumnStyle)
MappingName MappingName MappingName MappingName

获取或设置列样式所映射到的数据成员的名称。Gets or sets the name of the data member to map the column style to.

(Inherited from DataGridColumnStyle)
NullText NullText NullText NullText

获取或设置在列包含 null 时所显示的文本。Gets or sets the text that is displayed when the column contains null.

(Inherited from DataGridColumnStyle)
NullValue NullValue NullValue NullValue

获取或设置在将列值设置为 Value 时使用的实际值。Gets or sets the actual value used when setting the value of the column to Value.

PropertyDescriptor PropertyDescriptor PropertyDescriptor PropertyDescriptor

获取或设置 PropertyDescriptor,它确定 DataGridColumnStyle 所显示数据的特性。Gets or sets the PropertyDescriptor that determines the attributes of data displayed by the DataGridColumnStyle.

(Inherited from DataGridColumnStyle)
ReadOnly ReadOnly ReadOnly ReadOnly

获取或设置一个值,该值指示该列中的数据是否可以编辑。Gets or sets a value indicating whether the data in the column can be edited.

(Inherited from DataGridColumnStyle)
Site Site Site Site

获取或设置 ComponentISiteGets or sets the ISite of the Component.

(Inherited from Component)
TrueValue TrueValue TrueValue TrueValue

获取或设置在将列值设置为 true 时使用的实际值。Gets or sets the actual value used when setting the value of the column to true.

Width Width Width Width

获取或设置列的宽度。Gets or sets the width of the column.

(Inherited from DataGridColumnStyle)

方法

Abort(Int32) Abort(Int32) Abort(Int32) Abort(Int32)

发出请求以中断一个编辑过程。Initiates a request to interrupt an edit procedure.

BeginUpdate() BeginUpdate() BeginUpdate() BeginUpdate()

一直挂起列的绘制,直到调用 EndUpdate() 方法为止。Suspends the painting of the column until the EndUpdate() method is called.

(Inherited from DataGridColumnStyle)
CheckValidDataSource(CurrencyManager) CheckValidDataSource(CurrencyManager) CheckValidDataSource(CurrencyManager) CheckValidDataSource(CurrencyManager)

如果 DataGrid 没有有效数据源,或该列未映射到数据源中的有效属性,将引发异常。Throws an exception if the 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(Control) ColumnStartedEditing(Control) ColumnStartedEditing(Control) ColumnStartedEditing(Control)

通知 DataGrid 用户已开始编辑该列。Informs the DataGrid that the user has begun editing the column.

(Inherited from DataGridColumnStyle)
Commit(CurrencyManager, Int32) Commit(CurrencyManager, Int32) Commit(CurrencyManager, Int32) Commit(CurrencyManager, Int32)

初始化一个请求以完成一个编辑过程。Initiates a request to complete an editing procedure.

ConcedeFocus() ConcedeFocus() ConcedeFocus() ConcedeFocus()

通知列必须放弃它承载的控件的焦点。Notifies a column that it must relinquish the focus to the control it is hosting.

CreateHeaderAccessibleObject() CreateHeaderAccessibleObject() CreateHeaderAccessibleObject() CreateHeaderAccessibleObject()

获取列的 AccessibleObjectGets the AccessibleObject for the column.

(Inherited from DataGridColumnStyle)
CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。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() Dispose() Dispose() Dispose()

释放由 Component 使用的所有资源。Releases all resources used by the Component.

(Inherited from Component)
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

释放由 Component 占用的非托管资源,还可以另外再释放托管资源。Releases the unmanaged resources used by the Component and optionally releases the managed resources.

(Inherited from Component)
Edit(CurrencyManager, Int32, Rectangle, Boolean) Edit(CurrencyManager, Int32, Rectangle, Boolean) Edit(CurrencyManager, Int32, Rectangle, Boolean) Edit(CurrencyManager, Int32, Rectangle, Boolean)

准备单元格以便进行编辑。Prepares a cell for editing.

(Inherited from DataGridColumnStyle)
Edit(CurrencyManager, Int32, Rectangle, Boolean, String) Edit(CurrencyManager, Int32, Rectangle, Boolean, String) Edit(CurrencyManager, Int32, Rectangle, Boolean, String) Edit(CurrencyManager, Int32, Rectangle, Boolean, String)

使用指定的 CurrencyManager、行号和 Rectangle 参数准备单元格以便进行编辑。Prepares the cell for editing using the specified CurrencyManager, row number, and Rectangle parameters.

(Inherited from DataGridColumnStyle)
Edit(CurrencyManager, Int32, Rectangle, Boolean, String, Boolean) Edit(CurrencyManager, Int32, Rectangle, Boolean, String, Boolean) Edit(CurrencyManager, Int32, Rectangle, Boolean, String, Boolean) Edit(CurrencyManager, Int32, Rectangle, Boolean, String, Boolean)

准备单元格以便编辑值。Prepares the cell for editing a value.

EndUpdate() EndUpdate() EndUpdate() EndUpdate()

继续绘制由调用 BeginUpdate() 方法而挂起的列。Resumes the painting of columns suspended by calling the BeginUpdate() method.

(Inherited from DataGridColumnStyle)
EnterNullValue() EnterNullValue() EnterNullValue() EnterNullValue()

向列中输入 ValueEnters a Value into the column.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetColumnValueAtRow(CurrencyManager, Int32) GetColumnValueAtRow(CurrencyManager, Int32) GetColumnValueAtRow(CurrencyManager, Int32) GetColumnValueAtRow(CurrencyManager, Int32)

获取指定行处的值。Gets the value at the specified row.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetMinimumHeight() GetMinimumHeight() GetMinimumHeight() GetMinimumHeight()

获取列中单元格的高度。Gets the height of a cell in a column.

GetPreferredHeight(Graphics, Object) GetPreferredHeight(Graphics, Object) GetPreferredHeight(Graphics, Object) GetPreferredHeight(Graphics, Object)

获取调整列大小时使用的高度。Gets the height used when resizing columns.

GetPreferredSize(Graphics, Object) GetPreferredSize(Graphics, Object) GetPreferredSize(Graphics, Object) GetPreferredSize(Graphics, Object)

获取单元格的最佳宽度和高度,此单元格包含特定值。Gets the optimum width and height of a cell given a specific value to contain.

GetService(Type) GetService(Type) GetService(Type) GetService(Type)

返回一个对象,该对象表示由 Component 或它的 Container 提供的服务。Returns an object that represents a service provided by the Component or by its Container.

(Inherited from Component)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
Invalidate() Invalidate() Invalidate() Invalidate()

重新绘制列,并会向控件发送一条绘制消息。Redraws the column and causes a paint message to be sent to the control.

(Inherited from DataGridColumnStyle)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
Paint(Graphics, Rectangle, CurrencyManager, Int32) Paint(Graphics, Rectangle, CurrencyManager, Int32) Paint(Graphics, Rectangle, CurrencyManager, Int32) Paint(Graphics, Rectangle, CurrencyManager, Int32)

通过指定的 DataGridBoolColumnGraphics 和行号绘制 RectangleDraws the DataGridBoolColumn with the given Graphics, Rectangle and row number.

Paint(Graphics, Rectangle, CurrencyManager, Int32, Boolean) Paint(Graphics, Rectangle, CurrencyManager, Int32, Boolean) Paint(Graphics, Rectangle, CurrencyManager, Int32, Boolean) Paint(Graphics, Rectangle, CurrencyManager, Int32, Boolean)

使用给定的 DataGridBoolColumnGraphics、行号和对齐方式设置绘制 RectangleDraws the DataGridBoolColumn with the given Graphics, Rectangle, row number, and alignment settings.

Paint(Graphics, Rectangle, CurrencyManager, Int32, Brush, Brush, Boolean) Paint(Graphics, Rectangle, CurrencyManager, Int32, Brush, Brush, Boolean) Paint(Graphics, Rectangle, CurrencyManager, Int32, Brush, Brush, Boolean) Paint(Graphics, Rectangle, CurrencyManager, Int32, Brush, Brush, Boolean)

使用给定的 DataGridBoolColumnGraphics、行号、RectangleBrush 绘制 ColorDraws the DataGridBoolColumn with the given Graphics, Rectangle, row number, Brush, and Color.

ReleaseHostedControl() ReleaseHostedControl() ReleaseHostedControl() ReleaseHostedControl()

不再需要列所承载的控件时,允许列释放资源。Allows the column to free resources when the control it hosts is not needed.

(Inherited from DataGridColumnStyle)
ResetHeaderText() ResetHeaderText() ResetHeaderText() ResetHeaderText()

HeaderText 重置为其默认值 nullResets the HeaderText to its default value, null.

(Inherited from DataGridColumnStyle)
SetColumnValueAtRow(CurrencyManager, Int32, Object) SetColumnValueAtRow(CurrencyManager, Int32, Object) SetColumnValueAtRow(CurrencyManager, Int32, Object) SetColumnValueAtRow(CurrencyManager, Int32, Object)

设置指定行的值。Sets the value of a specified row.

SetDataGrid(DataGrid) SetDataGrid(DataGrid) SetDataGrid(DataGrid) SetDataGrid(DataGrid)

设置该列所属的 DataGrid 控件。Sets the DataGrid control that this column belongs to.

(Inherited from DataGridColumnStyle)
SetDataGridInColumn(DataGrid) SetDataGridInColumn(DataGrid) SetDataGridInColumn(DataGrid) SetDataGridInColumn(DataGrid)

设置列的 DataGridSets the DataGrid for the column.

(Inherited from DataGridColumnStyle)
ToString() ToString() ToString() ToString()

返回包含 Component 的名称的 String(如果有)。Returns a String containing the name of the Component, if any. 不应重写此方法。This method should not be overridden.

(Inherited from Component)
UpdateUI(CurrencyManager, Int32, String) UpdateUI(CurrencyManager, Int32, String) UpdateUI(CurrencyManager, Int32, String) UpdateUI(CurrencyManager, Int32, String)

用给定的文本更新指定行的值。Updates the value of a specified row with the given text.

(Inherited from DataGridColumnStyle)

事件

AlignmentChanged AlignmentChanged AlignmentChanged AlignmentChanged

Alignment 属性值更改时发生。Occurs when the Alignment property value changes.

(Inherited from DataGridColumnStyle)
AllowNullChanged AllowNullChanged AllowNullChanged AllowNullChanged

AllowNull 属性更改时发生。Occurs when the AllowNull property is changed.

Disposed Disposed Disposed Disposed

当通过调用 Dispose() 方法释放组件时发生。Occurs when the component is disposed by a call to the Dispose() method.

(Inherited from Component)
FalseValueChanged FalseValueChanged FalseValueChanged FalseValueChanged

FalseValue 属性更改时发生。Occurs when the FalseValue property is changed.

FontChanged FontChanged FontChanged FontChanged

当列的字体更改时发生。Occurs when the column's font changes.

(Inherited from DataGridColumnStyle)
HeaderTextChanged HeaderTextChanged HeaderTextChanged HeaderTextChanged

HeaderText 属性值更改时发生。Occurs when the HeaderText property value changes.

(Inherited from DataGridColumnStyle)
MappingNameChanged MappingNameChanged MappingNameChanged MappingNameChanged

MappingName 值更改时发生。Occurs when the MappingName value changes.

(Inherited from DataGridColumnStyle)
NullTextChanged NullTextChanged NullTextChanged NullTextChanged

NullText 值更改时发生。Occurs when the NullText value changes.

(Inherited from DataGridColumnStyle)
PropertyDescriptorChanged PropertyDescriptorChanged PropertyDescriptorChanged PropertyDescriptorChanged

PropertyDescriptor 属性值更改时发生。Occurs when the PropertyDescriptor property value changes.

(Inherited from DataGridColumnStyle)
ReadOnlyChanged ReadOnlyChanged ReadOnlyChanged ReadOnlyChanged

ReadOnly 属性值更改时发生。Occurs when the ReadOnly property value changes.

(Inherited from DataGridColumnStyle)
TrueValueChanged TrueValueChanged TrueValueChanged TrueValueChanged

TrueValue 属性值更改时发生。Occurs when the TrueValue property value is changed.

WidthChanged WidthChanged WidthChanged WidthChanged

Width 属性值更改时发生。Occurs when the Width property value changes.

(Inherited from DataGridColumnStyle)

显式界面实现

IDataGridColumnStyleEditingNotificationService.ColumnStartedEditing(Control) IDataGridColumnStyleEditingNotificationService.ColumnStartedEditing(Control) IDataGridColumnStyleEditingNotificationService.ColumnStartedEditing(Control) IDataGridColumnStyleEditingNotificationService.ColumnStartedEditing(Control)

通知 DataGrid 控件用户已开始编辑该列。Informs the DataGrid control that the user has begun editing the column.

(Inherited from DataGridColumnStyle)

适用于

另请参阅