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 IDisposable
Public MustInherit Class DataGridViewCell
Inherits DataGridViewElement
Implements ICloneable, IDisposable
- 繼承
- 衍生
- 屬性
- 實作
下列程式碼範例說明如何使用此類型。 如需此範例的詳細資訊,請參閱How to: Add ToolTips to Individual Cells in a Windows Forms DataGridView Control。
// 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() 方法,以便基類的屬性複製到新的儲存格。
Data |
初始化 DataGridViewCell 類別的新執行個體。 |
Accessibility |
取得指定給 DataGridViewCell.DataGridViewCellAccessibleObject 的 DataGridViewCell。 |
Column |
取得這個儲存格的資料行索引。 |
Content |
取得圍住儲存格內容區域的周框。 |
Context |
取得或設定與儲存格相關聯的捷徑功能表。 |
Data |
取得與這個項目有關聯的 DataGridView 控制項。 (繼承來源 DataGridViewElement) |
Default |
取得新資料錄之資料列中儲存格的預設值。 |
Displayed |
取得值,該值表示儲存格目前是否顯示於螢幕上。 |
Edited |
取得目前已格式化的儲存格值,不管儲存格是否處於編輯模式,而值是否尚未認可。 |
Edit |
取得儲存格的裝載編輯控制項型別。 |
Error |
取得儲存格之錯誤圖示的界限。 |
Error |
取得或設定文字,描述與儲存格相關聯的錯誤狀況。 |
Formatted |
取得儲存格的格式化值,以供顯示。 |
Formatted |
取得與儲存格相關聯之格式化值的類型。 |
Frozen |
取得指出是否已凍結此儲存格的值。 |
Has |
取得指出是否已經設定 Style 屬性的值。 |
Inherited |
取得儲存格的目前狀態,是繼承其資料列和資料行的狀態。 |
Inherited |
取得目前套用至儲存格的樣式。 |
Is |
取得指出目前是否正在編輯這個儲存格的值。 |
Owning |
取得包含這個儲存格的資料行。 |
Owning |
取得包含這個儲存格的資料列。 |
Preferred |
取得能夠容納儲存格的矩形區域大小 (以像素為單位)。 |
Read |
取得或設定值,指出是否可以編輯儲存格的資料。 |
Resizable |
取得指出儲存格是否可以調整大小的值。 |
Row |
取得儲存格的父資料列索引。 |
Selected |
取得或設定值,指出是否已選取此儲存格。 |
Size |
取得儲存格的大小。 |
State |
取得此項目的使用者介面 (UI) 狀態。 (繼承來源 DataGridViewElement) |
Style |
取得或設定儲存格的樣式。 |
Tag |
取得或設定物件,其中包含儲存格的相關補充資料。 |
Tool |
取得或設定與這個儲存格相關聯的工具提示文字。 |
Value |
取得或設定與這個儲存格相關聯的值。 |
Value |
取得或設定儲存格中值的資料類型。 |
Visible |
取得指出儲存格是在已隱藏資料列或是資料行中的值。 |
產品 | 版本 |
---|---|
.NET Framework | 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |