DataGridTextBoxColumn 类

定义

TextBox 的单元格中承载 DataGridColumnStyle 控件以便编辑字符串。Hosts a TextBox control in a cell of a DataGridColumnStyle for editing strings.

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

示例

下面的示例创建一个DataGridTextBoxColumn ,并将其添加GridColumnStylesCollectionDataGrid的。The following example creates a DataGridTextBoxColumn and adds it to the GridColumnStylesCollection of a DataGrid. 若要运行此代码示例,请将其粘贴到具有DataGrid名为dataGrid1的窗体中,并从的Form构造函数调用它。To run this code example, paste it into a form that has a DataGrid named dataGrid1 and call it from the constructor of the Form.

private:
   void AddColumn()
   {
      DataTable^ myTable = gcnew DataTable;
      
      // Add a new DataColumn to the DataTable.
      DataColumn^ myColumn = gcnew DataColumn( "myTextBoxColumn" );
      myColumn->DataType = System::Type::GetType( "System::String" );
      myColumn->DefaultValue = "default string";
      myTable->Columns->Add( myColumn );
      
      // Get the CurrencyManager for the DataTable.
      CurrencyManager^ cm = dynamic_cast<CurrencyManager^>(this->BindingContext[ myTable ]);
      
      // Use the CurrencyManager to get the PropertyDescriptor for the new column.
      System::ComponentModel::PropertyDescriptor^ pd = cm->GetItemProperties()[ "myTextBoxColumn" ];
      DataGridTextBoxColumn^ myColumnTextColumn;
      
      // Create the DataGridTextBoxColumn with the PropertyDescriptor.
      myColumnTextColumn = gcnew DataGridTextBoxColumn( pd );
      
      // Add the new DataGridColumn to the GridColumnsCollection.
      dataGrid1->DataSource = myTable;
      dataGrid1->TableStyles->Add( gcnew DataGridTableStyle );
      dataGrid1->TableStyles[ 0 ]->GridColumnStyles->Add( myColumnTextColumn );
   }

private void AddColumn()
{
     DataTable myTable= new DataTable();
 
     // Add a new DataColumn to the DataTable.
     DataColumn myColumn = new DataColumn("myTextBoxColumn");
     myColumn.DataType = System.Type.GetType("System.String");
     myColumn.DefaultValue="default string";
     myTable.Columns.Add(myColumn);
     // Get the CurrencyManager for the DataTable.
     CurrencyManager cm = (CurrencyManager)this.BindingContext[myTable];
     // Use the CurrencyManager to get the PropertyDescriptor for the new column.
     PropertyDescriptor pd = cm.GetItemProperties()["myTextBoxColumn"];
     DataGridTextBoxColumn myColumnTextColumn;
     // Create the DataGridTextBoxColumn with the PropertyDescriptor.
     myColumnTextColumn = new DataGridTextBoxColumn(pd);
     // Add the new DataGridColumn to the GridColumnsCollection.
     dataGrid1.DataSource= myTable;
     dataGrid1.TableStyles.Add(new DataGridTableStyle());
     dataGrid1.TableStyles[0].GridColumnStyles.Add(myColumnTextColumn);
 }

Private Sub AddColumn()
    Dim myTable As New DataTable()
    
    ' Add a new DataColumn to the DataTable.
    Dim myColumn As New DataColumn("myTextBoxColumn")
    myColumn.DataType = System.Type.GetType("System.String")
    myColumn.DefaultValue = "default string"
    myTable.Columns.Add(myColumn)
    ' Get the CurrencyManager for the DataTable.
    Dim cm As CurrencyManager = CType(Me.BindingContext(myTable), CurrencyManager)
    ' Use the CurrencyManager to get the PropertyDescriptor for the new column.
    Dim pd As PropertyDescriptor = cm.GetItemProperties()("myTextBoxColumn")
    Dim myColumnTextColumn As DataGridTextBoxColumn
    ' Create the DataGridTextBoxColumn with the PropertyDescriptor.
    myColumnTextColumn = New DataGridTextBoxColumn(pd)
    ' Add the new DataGridColumn to the GridColumnsCollection.
    dataGrid1.DataSource = myTable
    dataGrid1.TableStyles.Add(New DataGridTableStyle())
    dataGrid1.TableStyles(0).GridColumnStyles.Add(myColumnTextColumn)
End Sub

注解

DataGridTextBoxColumn类派生abstract自类DataGridColumnStyleThe DataGridTextBoxColumn class derives from the abstract class DataGridColumnStyle. 在运行时, DataGridTextBoxColumn DataGridTextBox承载允许用户编辑文本的控件。At run time, the DataGridTextBoxColumn hosts a DataGridTextBox control that allows users to edit text.

添加到类的特殊属性包括Format、和HideEditBoxSpecial properties added to the class include Format, and HideEditBox. 使用这些属性可以访问承载DataGridTextBox的控件及其属性,并设置显示值的格式。These properties allow you to access the hosted DataGridTextBox control and its attributes, and set the format for displaying values.

如果数据源是DataTable一个包含DataColumn对象, DataType则的DataColumn属性应设置为可在文本框控件中以逻辑方式编辑的数据类型。If the data source is a DataTable containing DataColumn objects, the DataType property of the DataColumn should be set to a data type that can logically be edited in a text box control. 以下数据类型自动与 a DataGridTextBoxColumn关联: Int16 Double DateTime Decimal ByteInt64、、 、、UInt16、、、、 Int32 UInt32 UInt64Single和。StringThe following data types are automatically associated with a DataGridTextBoxColumn : Byte, DateTime, Decimal, Double, Int16, Int32, Int64, UInt16, UInt32, UInt64, Single, and String.

备注

Visual Basic 不完全支持以下类型: DateTimeUInt16UInt32 UInt64、和TimeSpanThe following types are not fully supported by Visual Basic: DateTime, UInt16, UInt32, UInt64, and TimeSpan. (不允许使用运算符。)(Operators are not allowed.)

构造函数

DataGridTextBoxColumn()

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

DataGridTextBoxColumn(PropertyDescriptor)

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

DataGridTextBoxColumn(PropertyDescriptor, Boolean)

使用指定的 DataGridTextBoxColumn 初始化 PropertyDescriptor 类的新实例。Initializes a new instance of the DataGridTextBoxColumn class using the specified PropertyDescriptor. 指定 DataGridTextBoxColumn 是否为默认列。Specifies whether the DataGridTextBoxColumn is a default column.

DataGridTextBoxColumn(PropertyDescriptor, String)

使用指定的 DataGridTextBoxColumn 和格式初始化 PropertyDescriptor 的一个新实例。Initializes a new instance of a DataGridTextBoxColumn with the specified PropertyDescriptor and format.

DataGridTextBoxColumn(PropertyDescriptor, String, Boolean)

使用指定的 DataGridTextBoxColumn 和格式初始化 PropertyDescriptor 类的新实例。Initializes a new instance of the DataGridTextBoxColumn class with a specified PropertyDescriptor and format. 指定此列是否为默认列。Specifies whether the column is the default column.

属性

Alignment

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

(继承自 DataGridColumnStyle)
CanRaiseEvents

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

(继承自 Component)
Container

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

(继承自 Component)
DataGridTableStyle

获取列的 DataGridTableStyleGets the DataGridTableStyle for the column.

(继承自 DataGridColumnStyle)
DesignMode

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

(继承自 Component)
Events

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

(继承自 Component)
FontHeight

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

(继承自 DataGridColumnStyle)
Format

获取或设置指定格式化文本的方法的一个或多个字符。Gets or sets the character(s) that specify how text is formatted.

FormatInfo

获取或设置用于确定格式化值的方法的特定区域性信息。Gets or sets the culture specific information used to determine how values are formatted.

HeaderAccessibleObject

获取列的 AccessibleObjectGets the AccessibleObject for the column.

(继承自 DataGridColumnStyle)
HeaderText

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

(继承自 DataGridColumnStyle)
MappingName

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

(继承自 DataGridColumnStyle)
NullText

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

(继承自 DataGridColumnStyle)
PropertyDescriptor

获取或设置 PropertyDescriptorDataGridTextBoxColumnGets or sets the PropertyDescriptor for the DataGridTextBoxColumn.

ReadOnly

设置一个值,该值指示文本框列是否为只读。Sets a value indicating whether the text box column is read-only.

Site

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

(继承自 Component)
TextBox

获取寄宿的 TextBox 控件。Gets the hosted TextBox control.

Width

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

(继承自 DataGridColumnStyle)

方法

Abort(Int32)

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

BeginUpdate()

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

(继承自 DataGridColumnStyle)
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.

(继承自 DataGridColumnStyle)
ColumnStartedEditing(Control)

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

(继承自 DataGridColumnStyle)
Commit(CurrencyManager, Int32)

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

ConcedeFocus()

通知此列焦点正被让出。Informs the column that the focus is being conceded.

CreateHeaderAccessibleObject()

获取列的 AccessibleObjectGets the AccessibleObject for the column.

(继承自 DataGridColumnStyle)
CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(继承自 MarshalByRefObject)
Dispose()

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

(继承自 Component)
Dispose(Boolean)

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

(继承自 Component)
Edit(CurrencyManager, Int32, Rectangle, Boolean)

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

(继承自 DataGridColumnStyle)
Edit(CurrencyManager, Int32, Rectangle, Boolean, String)

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

(继承自 DataGridColumnStyle)
Edit(CurrencyManager, Int32, Rectangle, Boolean, String, Boolean)

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

EndEdit()

结束对 DataGridColumnStyle 的编辑操作。Ends an edit operation on the DataGridColumnStyle.

EndUpdate()

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

(继承自 DataGridColumnStyle)
EnterNullValue()

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

Equals(Object)

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

(继承自 Object)
GetColumnValueAtRow(CurrencyManager, Int32)

获取指定 CurrencyManager 中指定行内的值。Gets the value in the specified row from the specified CurrencyManager.

(继承自 DataGridColumnStyle)
GetHashCode()

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

(继承自 Object)
GetLifetimeService()

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

(继承自 MarshalByRefObject)
GetMinimumHeight()

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

GetPreferredHeight(Graphics, Object)

获取要用于自动调整大小的列的高度。Gets the height to be used in for automatically resizing columns.

GetPreferredSize(Graphics, Object)

返回相对于指定值的单元格在指定行中的最佳宽度和高度。Returns the optimum width and height of the cell in a specified row relative to the specified value.

GetService(Type)

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

(继承自 Component)
GetType()

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

(继承自 Object)
HideEditBox()

隐藏 DataGridTextBox 控件并将焦点移动到 DataGrid 控件。Hides the DataGridTextBox control and moves the focus to the DataGrid control.

InitializeLifetimeService()

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

(继承自 MarshalByRefObject)
Invalidate()

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

(继承自 DataGridColumnStyle)
MemberwiseClone()

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

(继承自 Object)
MemberwiseClone(Boolean)

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

(继承自 MarshalByRefObject)
Paint(Graphics, Rectangle, CurrencyManager, Int32)

绘制具有指定 DataGridColumnStyleGraphicsRectangle 和行号的 CurrencyManagerPaints the a DataGridColumnStyle with the specified Graphics, Rectangle, CurrencyManager, and row number.

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

绘制具有指定 DataGridColumnStyleGraphicsRectangle、行号和对齐方式的 CurrencyManagerPaints a DataGridColumnStyle with the specified Graphics, Rectangle, CurrencyManager, row number, and alignment.

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

绘制具有指定 DataGridColumnStyleGraphicsRectangle、行号、CurrencyManager 和前景色的 BrushPaints a DataGridColumnStyle with the specified Graphics, Rectangle, CurrencyManager, row number, Brush, and foreground color.

PaintText(Graphics, Rectangle, String, Boolean)

在给定位置处依据指定的对齐方式绘制文本和边框。Draws the text and rectangle at the given location with the specified alignment.

PaintText(Graphics, Rectangle, String, Brush, Brush, Boolean)

在指定位置用指定的颜色和对齐方式绘制文本和边框。Draws the text and rectangle at the specified location with the specified colors and alignment.

ReleaseHostedControl()

移除 DataGrid 保持的、对用于编辑数据的控件的引用。Removes the reference that the DataGrid holds to the control used to edit data.

ResetHeaderText()

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

(继承自 DataGridColumnStyle)
SetColumnValueAtRow(CurrencyManager, Int32, Object)

用来自指定 CurrencyManager 的值设置指定行中的值。Sets the value in a specified row with the value from a specified CurrencyManager.

(继承自 DataGridColumnStyle)
SetDataGrid(DataGrid)

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

(继承自 DataGridColumnStyle)
SetDataGridInColumn(DataGrid)

TextBox 控件的 DataGrid 中添加一个 Control.ControlCollection 控件。Adds a TextBox control to the DataGrid control's Control.ControlCollection.

ToString()

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

(继承自 Component)
UpdateUI(CurrencyManager, Int32, String)

更新用户界面。Updates the user interface.

事件

AlignmentChanged

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

(继承自 DataGridColumnStyle)
Disposed

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

(继承自 Component)
FontChanged

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

(继承自 DataGridColumnStyle)
HeaderTextChanged

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

(继承自 DataGridColumnStyle)
MappingNameChanged

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

(继承自 DataGridColumnStyle)
NullTextChanged

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

(继承自 DataGridColumnStyle)
PropertyDescriptorChanged

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

(继承自 DataGridColumnStyle)
ReadOnlyChanged

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

(继承自 DataGridColumnStyle)
WidthChanged

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

(继承自 DataGridColumnStyle)

显式界面实现

IDataGridColumnStyleEditingNotificationService.ColumnStartedEditing(Control)

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

(继承自 DataGridColumnStyle)

适用于

另请参阅