DataGridView 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
在可自訂的格線中顯示資料。
public ref class DataGridView : System::Windows::Forms::Control, System::ComponentModel::ISupportInitialize
[System.ComponentModel.ComplexBindingProperties("DataSource", "DataMember")]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Windows.Forms.Docking(System.Windows.Forms.DockingBehavior.Ask)]
public class DataGridView : System.Windows.Forms.Control, System.ComponentModel.ISupportInitialize
[System.ComponentModel.ComplexBindingProperties("DataSource", "DataMember")]
[System.Windows.Forms.Docking(System.Windows.Forms.DockingBehavior.Ask)]
public class DataGridView : System.Windows.Forms.Control, System.ComponentModel.ISupportInitialize
[<System.ComponentModel.ComplexBindingProperties("DataSource", "DataMember")>]
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Windows.Forms.Docking(System.Windows.Forms.DockingBehavior.Ask)>]
type DataGridView = class
inherit Control
interface ISupportInitialize
[<System.ComponentModel.ComplexBindingProperties("DataSource", "DataMember")>]
[<System.Windows.Forms.Docking(System.Windows.Forms.DockingBehavior.Ask)>]
type DataGridView = class
inherit Control
interface ISupportInitialize
Public Class DataGridView
Inherits Control
Implements ISupportInitialize
- 繼承
- 屬性
- 實作
範例
下列程式代碼範例示範如何初始化未系結 DataGridView 控件。
using System;
using System.Drawing;
using System.Windows.Forms;
public class Form1 : System.Windows.Forms.Form
{
private Panel buttonPanel = new Panel();
private DataGridView songsDataGridView = new DataGridView();
private Button addNewRowButton = new Button();
private Button deleteRowButton = new Button();
public Form1()
{
this.Load += new EventHandler(Form1_Load);
}
private void Form1_Load(System.Object sender, System.EventArgs e)
{
SetupLayout();
SetupDataGridView();
PopulateDataGridView();
}
private void songsDataGridView_CellFormatting(object sender,
System.Windows.Forms.DataGridViewCellFormattingEventArgs e)
{
if (e != null)
{
if (this.songsDataGridView.Columns[e.ColumnIndex].Name == "Release Date")
{
if (e.Value != null)
{
try
{
e.Value = DateTime.Parse(e.Value.ToString())
.ToLongDateString();
e.FormattingApplied = true;
}
catch (FormatException)
{
Console.WriteLine("{0} is not a valid date.", e.Value.ToString());
}
}
}
}
}
private void addNewRowButton_Click(object sender, EventArgs e)
{
this.songsDataGridView.Rows.Add();
}
private void deleteRowButton_Click(object sender, EventArgs e)
{
if (this.songsDataGridView.SelectedRows.Count > 0 &&
this.songsDataGridView.SelectedRows[0].Index !=
this.songsDataGridView.Rows.Count - 1)
{
this.songsDataGridView.Rows.RemoveAt(
this.songsDataGridView.SelectedRows[0].Index);
}
}
private void SetupLayout()
{
this.Size = new Size(600, 500);
addNewRowButton.Text = "Add Row";
addNewRowButton.Location = new Point(10, 10);
addNewRowButton.Click += new EventHandler(addNewRowButton_Click);
deleteRowButton.Text = "Delete Row";
deleteRowButton.Location = new Point(100, 10);
deleteRowButton.Click += new EventHandler(deleteRowButton_Click);
buttonPanel.Controls.Add(addNewRowButton);
buttonPanel.Controls.Add(deleteRowButton);
buttonPanel.Height = 50;
buttonPanel.Dock = DockStyle.Bottom;
this.Controls.Add(this.buttonPanel);
}
private void SetupDataGridView()
{
this.Controls.Add(songsDataGridView);
songsDataGridView.ColumnCount = 5;
songsDataGridView.ColumnHeadersDefaultCellStyle.BackColor = Color.Navy;
songsDataGridView.ColumnHeadersDefaultCellStyle.ForeColor = Color.White;
songsDataGridView.ColumnHeadersDefaultCellStyle.Font =
new Font(songsDataGridView.Font, FontStyle.Bold);
songsDataGridView.Name = "songsDataGridView";
songsDataGridView.Location = new Point(8, 8);
songsDataGridView.Size = new Size(500, 250);
songsDataGridView.AutoSizeRowsMode =
DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders;
songsDataGridView.ColumnHeadersBorderStyle =
DataGridViewHeaderBorderStyle.Single;
songsDataGridView.CellBorderStyle = DataGridViewCellBorderStyle.Single;
songsDataGridView.GridColor = Color.Black;
songsDataGridView.RowHeadersVisible = false;
songsDataGridView.Columns[0].Name = "Release Date";
songsDataGridView.Columns[1].Name = "Track";
songsDataGridView.Columns[2].Name = "Title";
songsDataGridView.Columns[3].Name = "Artist";
songsDataGridView.Columns[4].Name = "Album";
songsDataGridView.Columns[4].DefaultCellStyle.Font =
new Font(songsDataGridView.DefaultCellStyle.Font, FontStyle.Italic);
songsDataGridView.SelectionMode =
DataGridViewSelectionMode.FullRowSelect;
songsDataGridView.MultiSelect = false;
songsDataGridView.Dock = DockStyle.Fill;
songsDataGridView.CellFormatting += new
DataGridViewCellFormattingEventHandler(
songsDataGridView_CellFormatting);
}
private void PopulateDataGridView()
{
string[] row0 = { "11/22/1968", "29", "Revolution 9",
"Beatles", "The Beatles [White Album]" };
string[] row1 = { "1960", "6", "Fools Rush In",
"Frank Sinatra", "Nice 'N' Easy" };
string[] row2 = { "11/11/1971", "1", "One of These Days",
"Pink Floyd", "Meddle" };
string[] row3 = { "1988", "7", "Where Is My Mind?",
"Pixies", "Surfer Rosa" };
string[] row4 = { "5/1981", "9", "Can't Find My Mind",
"Cramps", "Psychedelic Jungle" };
string[] row5 = { "6/10/2003", "13",
"Scatterbrain. (As Dead As Leaves.)",
"Radiohead", "Hail to the Thief" };
string[] row6 = { "6/30/1992", "3", "Dress", "P J Harvey", "Dry" };
songsDataGridView.Rows.Add(row0);
songsDataGridView.Rows.Add(row1);
songsDataGridView.Rows.Add(row2);
songsDataGridView.Rows.Add(row3);
songsDataGridView.Rows.Add(row4);
songsDataGridView.Rows.Add(row5);
songsDataGridView.Rows.Add(row6);
songsDataGridView.Columns[0].DisplayIndex = 3;
songsDataGridView.Columns[1].DisplayIndex = 4;
songsDataGridView.Columns[2].DisplayIndex = 0;
songsDataGridView.Columns[3].DisplayIndex = 1;
songsDataGridView.Columns[4].DisplayIndex = 2;
}
[STAThreadAttribute()]
static void Main()
{
Application.EnableVisualStyles();
Application.Run(new Form1());
}
}
Imports System.Drawing
Imports System.Windows.Forms
Public Class Form1
Inherits System.Windows.Forms.Form
Private buttonPanel As New Panel
Private WithEvents songsDataGridView As New DataGridView
Private WithEvents addNewRowButton As New Button
Private WithEvents deleteRowButton As New Button
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
SetupLayout()
SetupDataGridView()
PopulateDataGridView()
End Sub
Private Sub songsDataGridView_CellFormatting(ByVal sender As Object, _
ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) _
Handles songsDataGridView.CellFormatting
If e IsNot Nothing Then
If Me.songsDataGridView.Columns(e.ColumnIndex).Name = _
"Release Date" Then
If e.Value IsNot Nothing Then
Try
e.Value = DateTime.Parse(e.Value.ToString()) _
.ToLongDateString()
e.FormattingApplied = True
Catch ex As FormatException
Console.WriteLine("{0} is not a valid date.", e.Value.ToString())
End Try
End If
End If
End If
End Sub
Private Sub addNewRowButton_Click(ByVal sender As Object, _
ByVal e As EventArgs) Handles addNewRowButton.Click
Me.songsDataGridView.Rows.Add()
End Sub
Private Sub deleteRowButton_Click(ByVal sender As Object, _
ByVal e As EventArgs) Handles deleteRowButton.Click
If Me.songsDataGridView.SelectedRows.Count > 0 AndAlso _
Not Me.songsDataGridView.SelectedRows(0).Index = _
Me.songsDataGridView.Rows.Count - 1 Then
Me.songsDataGridView.Rows.RemoveAt( _
Me.songsDataGridView.SelectedRows(0).Index)
End If
End Sub
Private Sub SetupLayout()
Me.Size = New Size(600, 500)
With addNewRowButton
.Text = "Add Row"
.Location = New Point(10, 10)
End With
With deleteRowButton
.Text = "Delete Row"
.Location = New Point(100, 10)
End With
With buttonPanel
.Controls.Add(addNewRowButton)
.Controls.Add(deleteRowButton)
.Height = 50
.Dock = DockStyle.Bottom
End With
Me.Controls.Add(Me.buttonPanel)
End Sub
Private Sub SetupDataGridView()
Me.Controls.Add(songsDataGridView)
songsDataGridView.ColumnCount = 5
With songsDataGridView.ColumnHeadersDefaultCellStyle
.BackColor = Color.Navy
.ForeColor = Color.White
.Font = New Font(songsDataGridView.Font, FontStyle.Bold)
End With
With songsDataGridView
.Name = "songsDataGridView"
.Location = New Point(8, 8)
.Size = New Size(500, 250)
.AutoSizeRowsMode = _
DataGridViewAutoSizeRowsMode.DisplayedCellsExceptHeaders
.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.Single
.CellBorderStyle = DataGridViewCellBorderStyle.Single
.GridColor = Color.Black
.RowHeadersVisible = False
.Columns(0).Name = "Release Date"
.Columns(1).Name = "Track"
.Columns(2).Name = "Title"
.Columns(3).Name = "Artist"
.Columns(4).Name = "Album"
.Columns(4).DefaultCellStyle.Font = _
New Font(Me.songsDataGridView.DefaultCellStyle.Font, FontStyle.Italic)
.SelectionMode = DataGridViewSelectionMode.FullRowSelect
.MultiSelect = False
.Dock = DockStyle.Fill
End With
End Sub
Private Sub PopulateDataGridView()
Dim row0 As String() = {"11/22/1968", "29", "Revolution 9", _
"Beatles", "The Beatles [White Album]"}
Dim row1 As String() = {"1960", "6", "Fools Rush In", _
"Frank Sinatra", "Nice 'N' Easy"}
Dim row2 As String() = {"11/11/1971", "1", "One of These Days", _
"Pink Floyd", "Meddle"}
Dim row3 As String() = {"1988", "7", "Where Is My Mind?", _
"Pixies", "Surfer Rosa"}
Dim row4 As String() = {"5/1981", "9", "Can't Find My Mind", _
"Cramps", "Psychedelic Jungle"}
Dim row5 As String() = {"6/10/2003", "13", _
"Scatterbrain. (As Dead As Leaves.)", _
"Radiohead", "Hail to the Thief"}
Dim row6 As String() = {"6/30/1992", "3", "Dress", "P J Harvey", "Dry"}
With Me.songsDataGridView.Rows
.Add(row0)
.Add(row1)
.Add(row2)
.Add(row3)
.Add(row4)
.Add(row5)
.Add(row6)
End With
With Me.songsDataGridView
.Columns(0).DisplayIndex = 3
.Columns(1).DisplayIndex = 4
.Columns(2).DisplayIndex = 0
.Columns(3).DisplayIndex = 1
.Columns(4).DisplayIndex = 2
End With
End Sub
<STAThreadAttribute()> _
Public Shared Sub Main()
Application.EnableVisualStyles()
Application.Run(New Form1())
End Sub
End Class
備註
控制項 DataGridView 提供可自定義的數據表來顯示數據。 類別DataGridView允許透過使用、ColumnHeadersDefaultCellStyle、 CellBorderStyle和 等DefaultCellStyle屬性來自定義儲存格、資料列、資料行和GridColor框線。 如需詳細資訊,請參閱 Windows Forms DataGridView 控件中的基本格式設定和樣式。
您可以使用 DataGridView 控制項來顯示具有或不含基礎資料來源的數據。 若未指定資料來源,您可以建立包含資料的資料列和資料列,並使用和 Columns 屬性直接將它們加入至 。DataGridViewRows 您也可以使用 Rows 集合來存取 DataGridViewRow 物件和 DataGridViewRow.Cells 屬性,以直接讀取或寫入儲存格值。 索引 Item[] 器也可直接存取儲存格。
除了手動填入控件,您也可以設定 DataSource 和 DataMember 屬性,將 系結 DataGridView 至數據源,並自動填入數據。 如需詳細資訊,請參閱在 Windows Forms DataGridView 控件中顯示數據。
使用非常大量的資料時,您可以將 屬性設定 VirtualMode 為 true
,以顯示可用數據的子集。 虛擬模式需要實作填入控件的數據快取 DataGridView 。 如需詳細資訊,請參閱 data Display Modes in the Windows Forms DataGridView Control。
如需控件中 DataGridView 可用功能的其他資訊,請參閱 DataGridView 控件。 下表提供一般工作的直接連結。
控件 DataGridView 會取代 並擴充 DataGrid 控件。 如需詳細資訊,請參閱 Windows Forms DataGridView 與 DataGrid 控件之間的差異。
注意
控件DataGridView會ContextMenu從 Control繼承和 ContextMenuStrip 屬性,但只ContextMenuStrip支援 屬性。 搭配控件使用 ContextMenu 屬性 DataGridView 沒有任何作用。
建構函式
DataGridView() |
初始化 DataGridView 類別的新執行個體。 |
屬性
AccessibilityObject |
取得指定給控制項的 AccessibleObject。 (繼承來源 Control) |
AccessibleDefaultActionDescription |
取得或設定協助用戶端應用程式所使用的控制項的預設動作描述。 (繼承來源 Control) |
AccessibleDescription |
取得或設定協助工具用戶端應用程式使用之控制項的描述。 (繼承來源 Control) |
AccessibleName |
取得或設定協助工具用戶端應用程式使用的控制項名稱。 (繼承來源 Control) |
AccessibleRole |
取得或設定控制項的可存取角色。 (繼承來源 Control) |
AdjustedTopLeftHeaderBorderStyle |
取得 DataGridView 中左上方儲存格的框線樣式。 |
AdvancedCellBorderStyle |
取得 DataGridView 中儲存格的框線樣式。 |
AdvancedColumnHeadersBorderStyle |
取得 DataGridView 中資料行標頭儲存格的框線樣式。 |
AdvancedRowHeadersBorderStyle |
取得 DataGridView 中資料列標頭儲存格的框線樣式。 |
AllowDrop |
取得或設定值,指出控制項是否能接受使用者拖放上來的資料。 (繼承來源 Control) |
AllowUserToAddRows |
取得或設定值,指出是否已為使用者顯示可加入資料列的選項。 |
AllowUserToDeleteRows |
取得或設定值,指出是否允許使用者從 DataGridView 中刪除資料列。 |
AllowUserToOrderColumns |
取得或設定值,指出是否已啟用手動重新調整資料行的位置。 |
AllowUserToResizeColumns |
取得或設定值,指出使用者是否可以調整資料行的大小。 |
AllowUserToResizeRows |
取得或設定值,指出使用者是否可以調整資料列的大小。 |
AlternatingRowsDefaultCellStyle |
取得或設定套用至 DataGridView 奇數資料列的預設儲存格樣式。 |
Anchor |
取得或設定控制項繫結至的容器邊緣,並決定控制項隨其父代重新調整大小的方式。 (繼承來源 Control) |
AutoGenerateColumns |
取得或設定值,指出當已設定 DataSource 或 DataMember 屬性時,是否會自動建立資料行。 |
AutoScrollOffset |
取得或設定此控制項在 ScrollControlIntoView(Control) 中要捲動到哪一個位置。 (繼承來源 Control) |
AutoSize |
這個屬性與這個類別無關。 |
AutoSizeColumnsMode |
取得或設定值,表示要如何判斷資料行的寬度。 |
AutoSizeRowsMode |
取得或設定值,指出要如何判斷資料列的高度。 |
BackColor |
取得或設定控制項的背景色彩。 |
BackgroundColor |
取得或設定 DataGridView 的背景色彩。 |
BackgroundImage |
取得或設定在控制項中顯示的背景影像。 |
BackgroundImageLayout |
取得或設定在 ImageLayout 列舉類型中所定義的背景影像配置。 |
BindingContext |
取得或設定控制項的 BindingContext。 (繼承來源 Control) |
BorderStyle |
取得或設定 DataGridView 的框線樣式。 |
Bottom |
取得控制項下邊緣和其容器工作區 (Client Area) 上邊緣之間的距離 (單位為像素)。 (繼承來源 Control) |
Bounds |
取得或設定控制項 (包括其非工作區項目) 相對於父控制項之大小和位置 (單位為像素)。 (繼承來源 Control) |
CanEnableIme |
取得值,這個值表示 ImeMode 屬性是否可以設定為使用中的值,以啟用 IME 支援。 |
CanFocus |
取得指示控制項是否能取得焦點的值。 (繼承來源 Control) |
CanRaiseEvents |
判斷是否可以在控制項上引發事件。 (繼承來源 Control) |
CanSelect |
取得指示能否選取控制項的值。 (繼承來源 Control) |
Capture |
取得或設定值,指出控制項是否捕捉住滑鼠。 (繼承來源 Control) |
CausesValidation |
取得或設定值,指出控制項取得焦點時,是否會在任何需要驗證的控制項上執行驗證。 (繼承來源 Control) |
CellBorderStyle |
取得 DataGridView 的儲存格框線樣式。 |
ClientRectangle |
取得表示控制項工作區的矩形。 (繼承來源 Control) |
ClientSize |
取得或設定控制項工作區的高度和寬度。 (繼承來源 Control) |
ClipboardCopyMode |
取得或設定值,指出使用者是否可以將儲存格文字值複製到 Clipboard,以及是否會包含資料列和資料行標頭文字。 |
ColumnCount |
取得或設定 DataGridView 中顯示的資料行數目。 |
ColumnHeadersBorderStyle |
取得資料行行首所套用的框線樣式。 |
ColumnHeadersDefaultCellStyle |
取得或設定預設資料行行首的樣式。 |
ColumnHeadersHeight |
取得或設定資料行標頭資料列的高度 (以像素為單位)。 |
ColumnHeadersHeightSizeMode |
取得或設定值,指出資料行標頭的高度是否可以調整,以及使用者是否可以調整此高度,或是會配合標頭內容,自動調整此高度。 |
ColumnHeadersVisible |
取得或設定值,指出是否顯示資料行行首的資料列。 |
Columns |
取得包含控制項中所有欄的集合。 |
CompanyName |
取得包含控制項之應用程式的公司名稱或建立者。 (繼承來源 Control) |
Container |
取得包含 IContainer 的 Component。 (繼承來源 Component) |
ContainsFocus |
取得指示控制項 (或其子控制項之一) 目前是否擁有輸入焦點的值。 (繼承來源 Control) |
ContextMenu |
取得或設定與控制項關聯的捷徑功能表。 (繼承來源 Control) |
ContextMenuStrip |
取得或設定與這個控制項相關的 ContextMenuStrip。 (繼承來源 Control) |
Controls |
取得控制項中包含的控制項集合。 (繼承來源 Control) |
Created |
取得值,指出是否已經建立控制項。 (繼承來源 Control) |
CreateParams |
建立控制代碼時,取得必要的建立參數。 (繼承來源 Control) |
CurrentCell |
取得或設定目前的現用儲存格。 |
CurrentCellAddress |
取得目前的現用儲存格的資料列和資料行的索引。 |
CurrentRow |
取得包含目前儲存格的資料列。 |
Cursor |
取得或設定滑鼠指標移至控制項上時顯示的游標。 (繼承來源 Control) |
DataBindings |
取得控制項的資料繫結 (Data Binding)。 (繼承來源 Control) |
DataContext |
取得或設定數據系結用途的數據內容。 這是環境屬性。 (繼承來源 Control) |
DataMember |
取得或設定資料來源中,DataGridView 會顯示資料之清單或資料表的名稱。 |
DataSource |
取得或設定 DataGridView 會為其顯示資料的資料來源。 |
DefaultCellStyle |
取得或設定 DataGridView 中的儲存格所要套用的預設儲存格樣式 (前提是未設定其他儲存格樣式屬性)。 |
DefaultCursor |
取得或設定控制項的預設游標。 (繼承來源 Control) |
DefaultImeMode |
取得控制項支援的預設輸入法 (IME) 模式。 (繼承來源 Control) |
DefaultMargin |
取得控制項之間的預設指定間距 (單位為像素)。 (繼承來源 Control) |
DefaultMaximumSize |
取得指定為控制項的預設大小之最大值的長度和高度 (單位為像素)。 (繼承來源 Control) |
DefaultMinimumSize |
取得指定為控制項的預設大小之最小值的長度和高度 (單位為像素)。 (繼承來源 Control) |
DefaultPadding |
取得控制項內容的預設內部間距,以像素為單位。 (繼承來源 Control) |
DefaultSize |
取得控制項的預設初始大小。 |
DesignMode |
取得值,指出 Component 目前是否處於設計模式。 (繼承來源 Component) |
DeviceDpi |
取得目前顯示控制項的顯示裝置的 DPI 值。 (繼承來源 Control) |
DisplayRectangle |
取得表示控制項顯示區域的矩形。 |
Disposing |
取得值,指出基底 Control 類別是否正在處置的過程中。 (繼承來源 Control) |
Dock |
取得或設定停駐在其父控制項的控制項框線,並決定控制項隨其父代重新調整大小的方式。 (繼承來源 Control) |
DoubleBuffered |
取得或設定值,指出這個控制項是否應使用次要緩衝區重繪其介面,以減少或防止重繪閃動 (Flicker)。 (繼承來源 Control) |
EditingControl |
如果具有編輯控制項的儲存格位於編輯模式下,則取得目前儲存格所裝載的控制項。 |
EditingPanel |
取得包含 EditingControl 的面板。 |
EditMode |
取得或設定值,表示要如何開始編輯儲存格。 |
Enabled |
取得或設定值,指出控制項是否可回應使用者互動。 (繼承來源 Control) |
EnableHeadersVisualStyles |
取得或設定值,指出已針對應用程式啟用視覺化樣式時,資料列和資料行行首是否使用使用者的目前佈景主題的視覺化樣式。 |
Events |
取得附加在這個 Component 上的事件處理常式清單。 (繼承來源 Component) |
FirstDisplayedCell |
取得或設定目前顯示在 DataGridView 中的第一個儲存格;這個儲存格通常位於左上角。 |
FirstDisplayedScrollingColumnHiddenWidth |
取得目前捲動到檢視範圍之外資料行部分的寬度。 |
FirstDisplayedScrollingColumnIndex |
取得或設定顯示在 DataGridView 上之第一個資料行的索引。 |
FirstDisplayedScrollingRowIndex |
取得或設定顯示在 DataGridView 上之第一個資料列的索引。 |
Focused |
取得指示控制項是否擁有輸入焦點的值。 (繼承來源 Control) |
Font |
取得或設定 DataGridView 顯示的文字字型。 |
FontHeight |
取得或設定控制項字型的高度。 (繼承來源 Control) |
ForeColor |
取得或設定 DataGridView 的前景色彩。 |
GridColor |
取得或設定區隔 DataGridView 儲存格的格線色彩。 |
Handle |
取得控制項要繫結的目標視窗控制代碼。 (繼承來源 Control) |
HasChildren |
取得指示控制項是否包含一或多個子控制項的值。 (繼承來源 Control) |
Height |
取得或設定控制項的高度。 (繼承來源 Control) |
HorizontalScrollBar |
取得控制項的水平捲軸。 |
HorizontalScrollingOffset |
取得或設定控制項要水平捲動的像素數。 |
ImeMode |
取得或設定控制項的輸入法 (IME) 模式。 (繼承來源 Control) |
ImeModeBase |
取得或設定控制項的 IME 模式。 (繼承來源 Control) |
InvokeRequired |
取得一個值。這個值會指示是否由於呼叫端是在建立控制項之執行緒以外的執行緒,因此在進行控制項的方法呼叫時,應呼叫叫用 (Invoke) 方法。 (繼承來源 Control) |
IsAccessible |
取得或設定值,指出可及性應用程式是否見得到控制項。 (繼承來源 Control) |
IsAncestorSiteInDesignMode |
指出此控件的其中一個上階是否已月臺,且該月臺位於 DesignMode 中。 這是唯讀的屬性。 (繼承來源 Control) |
IsCurrentCellDirty |
取得值,指出目前的儲存格是否有未經認可的變更。 |
IsCurrentCellInEditMode |
取得值,指出目前是否正在編輯現用儲存格。 |
IsCurrentRowDirty |
取得值,指出目前的資料列是否有未認可的變更。 |
IsDisposed |
取得指示控制項是否已經處置的值。 (繼承來源 Control) |
IsHandleCreated |
取得指示控制項是否有相關控制代碼的值。 (繼承來源 Control) |
IsMirrored |
取得值,指出是否左右反轉控制項。 (繼承來源 Control) |
Item[Int32, Int32] |
提供索引子以取得或設定位於具有指定索引之資料行和資料列交集處的儲存格。 |
Item[String, Int32] |
提供索引子以取得或設定位於具有指定索引的資料列以及具有指定名稱的資料行二者交集處的儲存格。 |
LayoutEngine |
取得控制項之配置引擎的快取執行個體。 (繼承來源 Control) |
Left |
取得或設定控制項左邊緣和其容器工作區 (Client Area) 左邊緣之間的距離 (單位為像素)。 (繼承來源 Control) |
Location |
取得或設定對應至控制項容器左上角之控制項左上角的座標。 (繼承來源 Control) |
Margin |
取得或設定控制項之間的空格。 (繼承來源 Control) |
MaximumSize |
取得或設定 GetPreferredSize(Size) 可以指定的上限大小。 (繼承來源 Control) |
MinimumSize |
取得或設定 GetPreferredSize(Size) 可以指定的下限大小。 (繼承來源 Control) |
MultiSelect |
取得或設定值,指出是否允許使用者同時選取一個以上的 DataGridView 儲存格、資料列或資料行。 |
Name |
取得或設定控制項的名稱。 (繼承來源 Control) |
NewRowIndex |
取得新記錄的資料列之索引。 |
Padding |
這個屬性與這個控制項無關。 |
Parent |
取得或設定控制項的父容器。 (繼承來源 Control) |
PreferredSize |
取得能夠容納控制項的矩形區域的大小。 (繼承來源 Control) |
ProductName |
取得包含控制項的組件的產品名稱。 (繼承來源 Control) |
ProductVersion |
取得包含控制項的組件的版本。 (繼承來源 Control) |
ReadOnly |
取得或設定值,指出使用者是否可以編輯 DataGridView 控制項的儲存格。 |
RecreatingHandle |
取得指示控制項目前是否正重新建立其控制代碼的值。 (繼承來源 Control) |
Region |
取得或設定與控制項關聯的視窗區域。 (繼承來源 Control) |
RenderRightToLeft |
已淘汰.
已淘汰.
此屬性現在已過時。 (繼承來源 Control) |
ResizeRedraw |
取得或設定值,指出控制項重設大小時,是否會重繪本身。 (繼承來源 Control) |
Right |
取得控制項右邊緣和其容器工作區 (Client Area) 左邊緣之間的距離 (單位為像素)。 (繼承來源 Control) |
RightToLeft |
取得或設定值,指出控制項的項目是否對齊,以支援使用由右至左字型的地區設定。 (繼承來源 Control) |
RowCount |
取得或設定 DataGridView 中顯示的資料列數目。 |
RowHeadersBorderStyle |
取得或設定資料列行首儲存格的框線樣式。 |
RowHeadersDefaultCellStyle |
取得或設定資料列行首儲存格所套用的預設樣式。 |
RowHeadersVisible |
取得或設定值,指出是否顯示包含資料列行首的資料行。 |
RowHeadersWidth |
取得或設定包含資料列行首的資料行寬度 (以像素為單位)。 |
RowHeadersWidthSizeMode |
取得或設定值,指出資料列標頭的寬度是否可以調整,以及使用者是否可以調整此寬度,或是會配合標頭內容,自動調整此寬度。 |
Rows |
取得集合,其中包含 DataGridView 控制項中的所有資料列。 |
RowsDefaultCellStyle |
取得或設定 DataGridView 的資料列儲存格所套用的預設樣式。 |
RowTemplate |
取得或設定表示控制項中所有資料列之樣板的資料列。 |
ScaleChildren |
取得值,以判斷子控制項的縮放。 (繼承來源 Control) |
ScrollBars |
取得或設定 DataGridView 控制項中要顯示的捲軸類型。 |
SelectedCells |
取得使用者所選的儲存格集合。 |
SelectedColumns |
取得使用者所選的資料行集合。 |
SelectedRows |
取得使用者所選的資料列集合。 |
SelectionMode |
取得或設定值,指出要如何選取 DataGridView 的儲存格。 |
ShowCellErrors |
取得或設定值,指出是否要顯示儲存格錯誤。 |
ShowCellToolTips |
取得或設定值,該值表示當滑鼠指標在儲存格上暫停,或使用者以鍵盤巡覽至儲存格時,是否會顯示工具提示。 |
ShowEditingIcon |
取得或設定值,指出正在編輯的儲存格之資料列行首中是否可以看到編輯圖像 (Glyph)。 |
ShowFocusCues |
取得指示控制項是否應顯示焦點矩形 (Focus Rectangle) 的值。 (繼承來源 Control) |
ShowKeyboardCues |
取得值,指出使用者介面是否處於可顯示或隱藏鍵盤快速鍵的適當狀態下。 (繼承來源 Control) |
ShowRowErrors |
取得或設定值,指出針對包含資料項目錯誤的每一個資料列,是否會在資料列標頭顯示錯誤圖像。 |
Site |
取得或設定控制項的站台。 (繼承來源 Control) |
Size |
取得或設定控制項的高度和寬度。 (繼承來源 Control) |
SortedColumn |
取得 DataGridView 內容目前排序所依據的資料行。 |
SortOrder |
取得值,指出 DataGridView 控制項中的項目是以遞增或遞減順序排序,或者根本不排序。 |
StandardTab |
取得或設定值,指出 TAB 鍵是否會將焦點移到定位順序中的下一個控制項,而不是將焦點移到控制項中的下一個儲存格。 |
TabIndex |
取得或設定控制項容器中的控制項定位順序。 (繼承來源 Control) |
TabStop |
取得或設定值,指出使用者是否能使用 TAB 鍵,將焦點 (Focus) 給予這個控制項。 (繼承來源 Control) |
Tag |
取得或設定物件,其包含控制項相關資料。 (繼承來源 Control) |
Text |
取得或設定與控制項相關的文字。 |
Top |
取得或設定控制項上邊緣和其容器工作區 (Client Area) 上邊緣之間的距離 (單位為像素)。 (繼承來源 Control) |
TopLeftHeaderCell |
取得或設定位於 DataGridView 控制項左上角的標頭儲存格。 |
TopLevelControl |
取得沒有其他 Windows Form 父控制項的父控制項。 通常,這會是內含控制項最外層的 Form。 (繼承來源 Control) |
UserSetCursor |
取得 Cursor 屬性的預設值或使用者指定的值。 |
UseWaitCursor |
取得或設定值,指出是否將等待游標用於目前控制項和所有子控制項。 (繼承來源 Control) |
VerticalScrollBar |
取得控制項的垂直捲軸。 |
VerticalScrollingOffset |
取得控制項要垂直捲動的像素數。 |
VirtualMode |
取得或設定值,指出您是否已經為 DataGridView 控制項提供您自己的資料管理作業。 |
Visible |
取得或設定值,這個值指出是否顯示控制項及其所有子控制項。 (繼承來源 Control) |
Width |
取得或設定控制項的寬度。 (繼承來源 Control) |
WindowTarget |
這個屬性與這個類別無關。 (繼承來源 Control) |
方法
事件
明確介面實作
IDropTarget.OnDragDrop(DragEventArgs) |
引發 DragDrop 事件。 (繼承來源 Control) |
IDropTarget.OnDragEnter(DragEventArgs) |
引發 DragEnter 事件。 (繼承來源 Control) |
IDropTarget.OnDragLeave(EventArgs) |
引發 DragLeave 事件。 (繼承來源 Control) |
IDropTarget.OnDragOver(DragEventArgs) |
引發 DragOver 事件。 (繼承來源 Control) |
ISupportInitialize.BeginInit() |
如需這個成員的說明,請參閱 BeginInit()。 |
ISupportInitialize.EndInit() |
如需這個成員的說明,請參閱 EndInit()。 |
適用於
另請參閱
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應