Breyta

Deila með


DataGridTextBoxColumn Class

Definition

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
Inheritance

Examples

The following example creates a DataGridTextBoxColumn and adds it to the GridColumnStylesCollection of a DataGrid. 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

Remarks

The DataGridTextBoxColumn class derives from the abstract class DataGridColumnStyle. At run time, the DataGridTextBoxColumn hosts a DataGridTextBox control that allows users to edit text.

Special properties added to the class include Format, and HideEditBox. These properties allow you to access the hosted DataGridTextBox control and its attributes, and set the format for displaying values.

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. The following data types are automatically associated with a DataGridTextBoxColumn : Byte, DateTime, Decimal, Double, Int16, Int32, Int64, UInt16, UInt32, UInt64, Single, and String.

Note

The following types are not fully supported by Visual Basic: DateTime, UInt16, UInt32, UInt64, and TimeSpan. (Operators are not allowed.)

Constructors

DataGridTextBoxColumn()

Initializes a new instance of the DataGridTextBoxColumn class.

DataGridTextBoxColumn(PropertyDescriptor, Boolean)

Initializes a new instance of the DataGridTextBoxColumn class using the specified PropertyDescriptor. Specifies whether the DataGridTextBoxColumn is a default column.

DataGridTextBoxColumn(PropertyDescriptor, String, Boolean)

Initializes a new instance of the DataGridTextBoxColumn class with a specified PropertyDescriptor and format. Specifies whether the column is the default column.

DataGridTextBoxColumn(PropertyDescriptor, String)

Initializes a new instance of the DataGridTextBoxColumn class with the specified PropertyDescriptor and format.

DataGridTextBoxColumn(PropertyDescriptor)

Initializes a new instance of the DataGridTextBoxColumn class with a specified PropertyDescriptor.

Properties

Alignment

Gets or sets the alignment of text in a column.

(Inherited from DataGridColumnStyle)
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)
FontHeight

Gets the height of the column's font.

(Inherited from 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

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 null.

(Inherited from DataGridColumnStyle)
PropertyDescriptor

Gets or sets the PropertyDescriptor for the DataGridTextBoxColumn.

ReadOnly

Sets a value indicating whether the text box column is read-only.

Site

Gets or sets the ISite of the Component.

(Inherited from Component)
TextBox

Gets the hosted TextBox control.

Width

Gets or sets the width of the column.

(Inherited from DataGridColumnStyle)

Methods

Abort(Int32)

Initiates a request to interrupt an edit procedure.

BeginUpdate()

Suspends the painting of the column until the EndUpdate() method is called.

(Inherited from DataGridColumnStyle)
CheckValidDataSource(CurrencyManager)

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)

Informs the DataGrid that the user has begun editing the column.

(Inherited from DataGridColumnStyle)
Commit(CurrencyManager, Int32)

Initiates a request to complete an editing procedure.

ConcedeFocus()

Informs the column that the focus is being conceded.

CreateHeaderAccessibleObject()

Gets the AccessibleObject for the column.

(Inherited from DataGridColumnStyle)
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()

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, String, Boolean)

Prepares a cell for editing.

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)

Prepares a cell for editing.

(Inherited from DataGridColumnStyle)
EndEdit()

Ends an edit operation on the DataGridColumnStyle.

EndUpdate()

Resumes the painting of columns suspended by calling the BeginUpdate() method.

(Inherited from DataGridColumnStyle)
EnterNullValue()

Enters a Value in the column.

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetColumnValueAtRow(CurrencyManager, Int32)

Gets the value in the specified row from the specified CurrencyManager.

(Inherited from DataGridColumnStyle)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetLifetimeService()
Obsolete.

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 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)

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)
HideEditBox()

Hides the DataGridTextBox control and moves the focus to the DataGrid control.

InitializeLifetimeService()
Obsolete.

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, Boolean)

Paints a DataGridColumnStyle with the specified Graphics, Rectangle, CurrencyManager, row number, and alignment.

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

Paints a DataGridColumnStyle with the specified Graphics, Rectangle, CurrencyManager, row number, Brush, and foreground color.

Paint(Graphics, Rectangle, CurrencyManager, Int32)

Paints the a DataGridColumnStyle with the specified Graphics, Rectangle, CurrencyManager, and row number.

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()

Removes the reference that the DataGrid holds to the control used to edit data.

ResetHeaderText()

Resets the HeaderText to its default value, null.

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

Sets the value in a specified row with the value from a specified CurrencyManager.

(Inherited from DataGridColumnStyle)
SetDataGrid(DataGrid)

Sets the DataGrid control that this column belongs to.

(Inherited from DataGridColumnStyle)
SetDataGridInColumn(DataGrid)

Adds a TextBox control to the DataGrid control's Control.ControlCollection.

ToString()

Returns a String containing the name of the Component, if any. This method should not be overridden.

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

Updates the user interface.

Events

AlignmentChanged

Occurs when the Alignment property value changes.

(Inherited from DataGridColumnStyle)
Disposed

Occurs when the component is disposed by a call to the Dispose() method.

(Inherited from Component)
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)
WidthChanged

Occurs when the Width property value changes.

(Inherited from DataGridColumnStyle)

Explicit Interface Implementations

IDataGridColumnStyleEditingNotificationService.ColumnStartedEditing(Control)

Informs the DataGrid control that the user has begun editing the column.

(Inherited from DataGridColumnStyle)

Applies to

See also