DataGridViewCell 类   
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示 DataGridView 控件中的单个单元格。
public ref class DataGridViewCell abstract : System::Windows::Forms::DataGridViewElement, ICloneable, IDisposable[System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.DataGridViewCellConverter))]
public abstract class DataGridViewCell : System.Windows.Forms.DataGridViewElement, ICloneable, IDisposable[<System.ComponentModel.TypeConverter(typeof(System.Windows.Forms.DataGridViewCellConverter))>]
type DataGridViewCell = class
    inherit DataGridViewElement
    interface ICloneable
    interface IDisposablePublic MustInherit Class DataGridViewCell
Inherits DataGridViewElement
Implements ICloneable, IDisposable- 继承
- 派生
- 属性
- 实现
示例
以下代码示例演示了此类型的用法。 有关此示例的详细信息,请参阅如何:向 Windows 窗体 DataGridView 控件中的单个单元格添加工具提示。
// Sets the ToolTip text for cells in the Rating column.
void dataGridView1_CellFormatting(Object^ /*sender*/, 
    DataGridViewCellFormattingEventArgs^ e)
{
    if ( (e->ColumnIndex == this->dataGridView1->Columns["Rating"]->Index)
        && e->Value != nullptr )
    {
        DataGridViewCell^ cell = 
            this->dataGridView1->Rows[e->RowIndex]->Cells[e->ColumnIndex];
        if (e->Value->Equals("*"))
        {                
            cell->ToolTipText = "very bad";
        }
        else if (e->Value->Equals("**"))
        {
            cell->ToolTipText = "bad";
        }
        else if (e->Value->Equals("***"))
        {
            cell->ToolTipText = "good";
        }
        else if (e->Value->Equals("****"))
        {
            cell->ToolTipText = "very good";
        }
    }
}
// Sets the ToolTip text for cells in the Rating column.
void dataGridView1_CellFormatting(object sender, 
    DataGridViewCellFormattingEventArgs e)
{
    if ( (e.ColumnIndex == this.dataGridView1.Columns["Rating"].Index)
        && e.Value != null )
    {
        DataGridViewCell cell = 
            this.dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex];
        if (e.Value.Equals("*"))
        {                
            cell.ToolTipText = "very bad";
        }
        else if (e.Value.Equals("**"))
        {
            cell.ToolTipText = "bad";
        }
        else if (e.Value.Equals("***"))
        {
            cell.ToolTipText = "good";
        }
        else if (e.Value.Equals("****"))
        {
            cell.ToolTipText = "very good";
        }
    }
}
' Sets the ToolTip text for cells in the Rating column.
Sub dataGridView1_CellFormatting(ByVal sender As Object, _
    ByVal e As DataGridViewCellFormattingEventArgs) _
    Handles dataGridView1.CellFormatting
    If e.ColumnIndex = Me.dataGridView1.Columns("Rating").Index _
        AndAlso (e.Value IsNot Nothing) Then
        With Me.dataGridView1.Rows(e.RowIndex).Cells(e.ColumnIndex)
            If e.Value.Equals("*") Then
                .ToolTipText = "very bad"
            ElseIf e.Value.Equals("**") Then
                .ToolTipText = "bad"
            ElseIf e.Value.Equals("***") Then
                .ToolTipText = "good"
            ElseIf e.Value.Equals("****") Then
                .ToolTipText = "very good"
            End If
        End With
    End If
End Sub
注解
类 DataGridViewCell 表示控件中的 DataGridView 单个单元格。 可以通过 的DataGridViewRow集合检索单元格Cells。
的行和列 DataGridViewCell 标识单元格在 中 DataGridView的位置。 典型的单元格包含特定于包含该单元格的行和列的数据。 可以通过设置单元格的属性并处理与其关联的事件,通过多种方式自定义该单元格。
实施者说明
从 DataGridViewCell 派生类并将新属性添加到派生类时,请务必重写 Clone() 方法,以在克隆操作期间复制新属性。 还应调用基类的 Clone() 方法,以便将基类的属性复制到新单元格。
构造函数
| DataGridViewCell() | 初始化 DataGridViewCell 类的新实例。 | 
属性
| AccessibilityObject | 获取分配给 DataGridViewCell.DataGridViewCellAccessibleObject 的 DataGridViewCell。 | 
| ColumnIndex | 获取此单元格的列索引。 | 
| ContentBounds | 获取环绕单元格内容区域的边框。 | 
| ContextMenuStrip | 获取或设置与单元格关联的快捷菜单。 | 
| DataGridView | 获取与此元素关联的 DataGridView 控件。(继承自 DataGridViewElement) | 
| DefaultNewRowValue | 获取新记录所在行中单元格的默认值。 | 
| Displayed | 获取一个值,该值指示当前该单元格是否显示在屏幕上。 | 
| EditedFormattedValue | 获取该单元格的当前格式化值,而不考虑该单元格是否处于编辑模式,也不论是否尚未提交此值。 | 
| EditType | 获取单元格的寄宿编辑控件的类型。 | 
| ErrorIconBounds | 获取单元格的错误图标的界限。 | 
| ErrorText | 获取或设置描述与该单元格关联的错误条件的文本。 | 
| FormattedValue | 获取为显示进行格式化的单元格的值。 | 
| FormattedValueType | 获取与单元格关联的格式化值的类型。 | 
| Frozen | 获取指示单元格是否已被冻结的值。 | 
| HasStyle | 获取指示是否已设置 Style 属性的值。 | 
| InheritedState | 获取该单元格从它的行和列的状态继承后的当前状态。 | 
| InheritedStyle | 获取当前应用于单元格的样式。 | 
| IsInEditMode | 获取一个值,该值指示此单元格当前是否处于编辑状态。 | 
| OwningColumn | 获取包含此单元格的列。 | 
| OwningRow | 获取包含此单元格的行。 | 
| PreferredSize | 获取适合该单元格的矩形区域的大小(以像素为单位)。 | 
| ReadOnly | 获取或设置一个值,该值表示是否可以编辑该单元格的数据。 | 
| Resizable | 获取一个值,该值指示是否可以调整单元格的大小。 | 
| RowIndex | 获取单元格父行的索引。 | 
| Selected | 获取或设置一个值,该值指示是否已选定该单元格。 | 
| Size | 获取单元格的大小。 | 
| State | 获取元素的用户界面 (UI) 状态。(继承自 DataGridViewElement) | 
| Style | 获取或设置单元格的样式。 | 
| Tag | 获取或设置包含有关单元格补充数据的对象。 | 
| ToolTipText | 获取或设置与此单元格关联的 ToolTip 文本。 | 
| Value | 获取或设置与此单元格关联的值。 | 
| ValueType | 获取或设置单元格中值的数据类型。 | 
| Visible | 获取一个值,该值指示单元格是否位于已隐藏的行或列中。 |