Bagikan melalui


GridTableStylesCollection Kelas

Definisi

Perhatian

DataGrid is provided for binary compatibility with .NET Framework and is not intended to be used directly from your code. Use DataGridView instead.

Mewakili kumpulan DataGridTableStyle objek dalam DataGrid kontrol.

public ref class GridTableStylesCollection : System::Windows::Forms::BaseCollection, System::Collections::IList
[System.ComponentModel.ListBindable(false)]
public class GridTableStylesCollection : System.Windows.Forms.BaseCollection, System.Collections.IList
[System.ComponentModel.ListBindable(false)]
[System.ComponentModel.Browsable(false)]
[System.Obsolete("`DataGrid` is provided for binary compatibility with .NET Framework and is not intended to be used directly from your code. Use `DataGridView` instead.", false, DiagnosticId="WFDEV006", UrlFormat="https://aka.ms/winforms-warnings/{0}")]
public class GridTableStylesCollection : System.Windows.Forms.BaseCollection, System.Collections.IList
[<System.ComponentModel.ListBindable(false)>]
type GridTableStylesCollection = class
    inherit BaseCollection
    interface IList
    interface ICollection
    interface IEnumerable
[<System.ComponentModel.ListBindable(false)>]
[<System.ComponentModel.Browsable(false)>]
[<System.Obsolete("`DataGrid` is provided for binary compatibility with .NET Framework and is not intended to be used directly from your code. Use `DataGridView` instead.", false, DiagnosticId="WFDEV006", UrlFormat="https://aka.ms/winforms-warnings/{0}")>]
type GridTableStylesCollection = class
    inherit BaseCollection
    interface IList
    interface ICollection
    interface IEnumerable
Public Class GridTableStylesCollection
Inherits BaseCollection
Implements IList
Warisan
GridTableStylesCollection
Atribut
Penerapan

Contoh

Contoh kode berikut membuat dua DataGridTableStyle objek dan menambahkan masing-masing ke GridTableStylesCollection yang dikembalikan oleh TableStyles properti DataGrid kontrol.

void AddCustomDataTableStyle()
{
   DataGridTableStyle^ ts1 = gcnew DataGridTableStyle;
   ts1->MappingName = "Customers";
   
   // Set other properties.
   ts1->AlternatingBackColor = Color::LightGray;
   
   /* Add a GridColumnStyle and set its MappingName
     to the name of a DataColumn in the DataTable.
     Set the HeaderText and Width properties. */
   DataGridColumnStyle^ boolCol = gcnew DataGridBoolColumn;
   boolCol->MappingName = "Current";
   boolCol->HeaderText = "IsCurrent Customer";
   boolCol->Width = 150;
   ts1->GridColumnStyles->Add( boolCol );
   
   // Add a second column style.
   DataGridColumnStyle^ TextCol = gcnew DataGridTextBoxColumn;
   TextCol->MappingName = "custName";
   TextCol->HeaderText = "Customer Name";
   TextCol->Width = 250;
   ts1->GridColumnStyles->Add( TextCol );
   
   // Create the second table style with columns.
   DataGridTableStyle^ ts2 = gcnew DataGridTableStyle;
   ts2->MappingName = "Orders";
   
   // Set other properties.
   ts2->AlternatingBackColor = Color::LightBlue;
   
   // Create new ColumnStyle objects.
   DataGridColumnStyle^ cOrderDate = gcnew DataGridTextBoxColumn;
   cOrderDate->MappingName = "OrderDate";
   cOrderDate->HeaderText = "Order Date";
   cOrderDate->Width = 100;
   ts2->GridColumnStyles->Add( cOrderDate );
   
   /*Use a PropertyDescriptor to create a formatted
     column. First get the PropertyDescriptorCollection
     for the data source and data member. */
   System::ComponentModel::PropertyDescriptorCollection^ pcol = this->
       BindingContext[myDataSet, "Customers::custToOrders"]->
       GetItemProperties();
   
   /* Create a formatted column using a PropertyDescriptor.
     The formatting character S"c" specifies a currency format. */
   DataGridColumnStyle^ csOrderAmount =
      gcnew DataGridTextBoxColumn( pcol[ "OrderAmount" ],"c",true );
   csOrderAmount->MappingName = "OrderAmount";
   csOrderAmount->HeaderText = "Total";
   csOrderAmount->Width = 100;
   ts2->GridColumnStyles->Add( csOrderAmount );
   
   /* Add the DataGridTableStyle instances to
     the GridTableStylesCollection. */
   myDataGrid->TableStyles->Add( ts1 );
   myDataGrid->TableStyles->Add( ts2 );
}
private void AddCustomDataTableStyle(){
   DataGridTableStyle ts1 = new DataGridTableStyle();
   ts1.MappingName = "Customers";
   // Set other properties.
   ts1.AlternatingBackColor = Color.LightGray;

   /* Add a GridColumnStyle and set its MappingName 
   to the name of a DataColumn in the DataTable. 
   Set the HeaderText and Width properties. */
   
   DataGridColumnStyle boolCol = new DataGridBoolColumn();
   boolCol.MappingName = "Current";
   boolCol.HeaderText = "IsCurrent Customer";
   boolCol.Width = 150;
   ts1.GridColumnStyles.Add(boolCol);
   
   // Add a second column style.
   DataGridColumnStyle TextCol = new DataGridTextBoxColumn();
   TextCol.MappingName = "custName";
   TextCol.HeaderText = "Customer Name";
   TextCol.Width = 250;
   ts1.GridColumnStyles.Add(TextCol);

   // Create the second table style with columns.
   DataGridTableStyle ts2 = new DataGridTableStyle();
   ts2.MappingName = "Orders";

   // Set other properties.
   ts2.AlternatingBackColor = Color.LightBlue;
   
   // Create new ColumnStyle objects.
   DataGridColumnStyle cOrderDate = 
   new DataGridTextBoxColumn();
   cOrderDate.MappingName = "OrderDate";
   cOrderDate.HeaderText = "Order Date";
   cOrderDate.Width = 100;
   ts2.GridColumnStyles.Add(cOrderDate);

   /*Use a PropertyDescriptor to create a formatted
   column. First get the PropertyDescriptorCollection
   for the data source and data member. */
   System.ComponentModel.PropertyDescriptorCollection pcol = 
      this.BindingContext[myDataSet, "Customers.custToOrders"]
      .GetItemProperties();
 
   /* Create a formatted column using a PropertyDescriptor.
   The formatting character "c" specifies a currency format. */     
   DataGridColumnStyle csOrderAmount = 
   new DataGridTextBoxColumn(pcol["OrderAmount"], "c", true);
   csOrderAmount.MappingName = "OrderAmount";
   csOrderAmount.HeaderText = "Total";
   csOrderAmount.Width = 100;
   ts2.GridColumnStyles.Add(csOrderAmount);

   /* Add the DataGridTableStyle instances to 
   the GridTableStylesCollection. */
   myDataGrid.TableStyles.Add(ts1);
   myDataGrid.TableStyles.Add(ts2);
}
Private Sub AddCustomDataTableStyle()
   Dim ts1 As New DataGridTableStyle()
   ts1.MappingName = "Customers"
   ' Set other properties.
   ts1.AlternatingBackColor = Color.LightGray
   ' Add a GridColumnStyle and set its MappingName 
   ' to the name of a DataColumn in the DataTable. 
   ' Set the HeaderText and Width properties. 
     
   Dim boolCol As New DataGridBoolColumn()
   boolCol.MappingName = "Current"
   boolCol.HeaderText = "IsCurrent Customer"
   boolCol.Width = 150
   ts1.GridColumnStyles.Add(boolCol)
     
   ' Add a second column style.
   Dim TextCol As New DataGridTextBoxColumn()
   TextCol.MappingName = "custName"
   TextCol.HeaderText = "Customer Name"
   TextCol.Width = 250
   ts1.GridColumnStyles.Add(TextCol)
     
   ' Create the second table style with columns.
   Dim ts2 As New DataGridTableStyle()
   ts2.MappingName = "Orders"
     
   ' Set other properties.
   ts2.AlternatingBackColor = Color.LightBlue
     
   ' Create new ColumnStyle objects.
   Dim cOrderDate As New DataGridTextBoxColumn()
   cOrderDate.MappingName = "OrderDate"
   cOrderDate.HeaderText = "Order Date"
   cOrderDate.Width = 100
   ts2.GridColumnStyles.Add(cOrderDate)

   ' Use a PropertyDescriptor to create a formatted
   ' column. First get the PropertyDescriptorCollection
   ' for the data source and data member. 
   Dim pcol As System.ComponentModel.PropertyDescriptorCollection = _
   Me.BindingContext(myDataSet, "Customers.custToOrders"). _
   GetItemProperties()

   ' Create a formatted column using a PropertyDescriptor.
   ' The formatting character "c" specifies a currency format. */     
     
   Dim csOrderAmount As _
   New DataGridTextBoxColumn(pcol("OrderAmount"), "c", True)
   csOrderAmount.MappingName = "OrderAmount"
   csOrderAmount.HeaderText = "Total"
   csOrderAmount.Width = 100
   ts2.GridColumnStyles.Add(csOrderAmount)
     
   ' Add the DataGridTableStyle instances to 
   ' the GridTableStylesCollection. 
   myDataGrid.TableStyles.Add(ts1)
   myDataGrid.TableStyles.Add(ts2)
End Sub

Keterangan

GridTableStylesCollection berisi DataGridTableStyle objek yang memungkinkan DataGrid kontrol menampilkan gaya kisi yang disesuaikan untuk masing-masing DataTable dalam DataSet.

DataGrid Pada kontrol, TableStyles properti mengembalikan GridTableStylesCollection.

Secara default, GridTableStylesCollection tidak berisi objek apa pun DataGridTableStyle . Sebagai gantinya, menampilkan DataGrid setiap tabel menggunakan pengaturan default untuk warna, lebar, dan pemformatan. Semua kolom setiap tabel ditampilkan. DataGridTableStyle Ketika ditambahkan ke koleksi, DataGrid menggunakan MappingName untuk menentukan objek mana yang memasok data untuk kisi. Misalnya, jika sumber data adalah DataSet yang berisi tiga DataTable objek, MappingName harus cocok dengan TableName salah satu objek. MappingName Jika tidak cocok dengan nilai TableName apa pun, pengaturan default akan digunakan untuk menampilkan data untuk setiap tabel, dan DataGridTableStyle pengaturan akan diabaikan.

Perhatian

Selalu buat DataGridColumnStyle objek dan tambahkan ke GridColumnStylesCollection sebelum menambahkan DataGridTableStyle objek ke GridTableStylesCollection. Saat Anda menambahkan kosong DataGridTableStyle dengan nilai yang valid MappingName ke koleksi, DataGridColumnStyle objek secara otomatis dibuat untuk Anda. Akibatnya, pengecualian akan dilemparkan jika Anda mencoba menambahkan objek baru DataGridColumnStyle dengan nilai duplikat MappingName ke GridColumnStylesCollection. Atau, hapus GridColumnStylesCollection menggunakan Clear metode .

Properti

Nama Deskripsi
Count
Kedaluwarsa.

Mendapatkan jumlah total elemen dalam koleksi.

(Diperoleh dari BaseCollection)
IsReadOnly
Kedaluwarsa.

Mendapatkan nilai yang menunjukkan apakah koleksi bersifat baca-saja.

(Diperoleh dari BaseCollection)
IsSynchronized
Kedaluwarsa.

Mendapatkan nilai yang menunjukkan apakah akses ke disinkronkan ICollection .

(Diperoleh dari BaseCollection)
Item[Int32]
Kedaluwarsa.

Mendapatkan yang DataGridTableStyle ditentukan oleh indeks.

Item[String]
Kedaluwarsa.

DataGridTableStyle Mendapatkan dengan nama yang ditentukan.

List
Kedaluwarsa.

Mendapatkan daftar yang mendasar.

List
Kedaluwarsa.

Mendapatkan daftar elemen yang terkandung dalam BaseCollection instans.

(Diperoleh dari BaseCollection)
SyncRoot
Kedaluwarsa.

Mendapatkan objek yang dapat digunakan untuk menyinkronkan akses ke BaseCollection.

(Diperoleh dari BaseCollection)

Metode

Nama Deskripsi
Add(DataGridTableStyle)
Kedaluwarsa.

DataGridTableStyle Menambahkan ke koleksi ini.

AddRange(DataGridTableStyle[])
Kedaluwarsa.

Menambahkan array gaya tabel ke koleksi.

Clear()
Kedaluwarsa.

Menghapus koleksi.

Contains(DataGridTableStyle)
Kedaluwarsa.

Mendapatkan nilai yang menunjukkan apakah GridTableStylesCollection berisi yang ditentukan DataGridTableStyle.

Contains(String)
Kedaluwarsa.

Mendapatkan nilai yang menunjukkan apakah GridTableStylesCollection berisi yang DataGridTableStyle ditentukan berdasarkan nama.

CopyTo(Array, Int32)
Kedaluwarsa.

Menyalin semua elemen satu dimensi Array saat ini ke satu dimensi Array yang ditentukan mulai dari indeks tujuan Array yang ditentukan.

(Diperoleh dari BaseCollection)
CreateObjRef(Type)
Kedaluwarsa.

Membuat objek yang berisi semua informasi relevan yang diperlukan untuk menghasilkan proksi yang digunakan untuk berkomunikasi dengan objek jarak jauh.

(Diperoleh dari MarshalByRefObject)
Equals(Object)
Kedaluwarsa.

Menentukan apakah objek yang ditentukan sama dengan objek saat ini.

(Diperoleh dari Object)
GetEnumerator()
Kedaluwarsa.

Mendapatkan objek yang memungkinkan iterasi melalui anggota koleksi.

(Diperoleh dari BaseCollection)
GetHashCode()
Kedaluwarsa.

Berfungsi sebagai fungsi hash default.

(Diperoleh dari Object)
GetLifetimeService()
Kedaluwarsa.

Mengambil objek layanan seumur hidup saat ini yang mengontrol kebijakan seumur hidup untuk instans ini.

(Diperoleh dari MarshalByRefObject)
GetType()
Kedaluwarsa.

Mendapatkan Type instans saat ini.

(Diperoleh dari Object)
InitializeLifetimeService()
Kedaluwarsa.

Mendapatkan objek layanan seumur hidup untuk mengontrol kebijakan seumur hidup untuk instans ini.

(Diperoleh dari MarshalByRefObject)
MemberwiseClone()
Kedaluwarsa.

Membuat salinan dangkal dari Objectsaat ini.

(Diperoleh dari Object)
MemberwiseClone(Boolean)
Kedaluwarsa.

Membuat salinan dangkal objek saat ini MarshalByRefObject .

(Diperoleh dari MarshalByRefObject)
OnCollectionChanged(CollectionChangeEventArgs)
Kedaluwarsa.

Menaikkan CollectionChanged acara.

Remove(DataGridTableStyle)
Kedaluwarsa.

DataGridTableStyleMenghapus .

RemoveAt(Int32)
Kedaluwarsa.

DataGridTableStyle Menghapus pada indeks yang ditentukan.

ToString()
Kedaluwarsa.

Mengembalikan string yang mewakili objek saat ini.

(Diperoleh dari Object)

Acara

Nama Deskripsi
CollectionChanged
Kedaluwarsa.

Terjadi ketika koleksi telah berubah.

Implementasi Antarmuka Eksplisit

Nama Deskripsi
ICollection.CopyTo(Array, Int32)
Kedaluwarsa.

Menyalin koleksi ke satu dimensi Arrayyang kompatibel , dimulai pada indeks array target yang ditentukan.

ICollection.Count
Kedaluwarsa.

Mendapatkan jumlah item dalam koleksi.

ICollection.IsSynchronized
Kedaluwarsa.

Mendapatkan nilai yang menunjukkan apakah akses ke GridTableStylesCollection disinkronkan (utas aman).

ICollection.SyncRoot
Kedaluwarsa.

Mendapatkan objek yang dapat digunakan untuk menyinkronkan akses ke koleksi.

IEnumerable.GetEnumerator()
Kedaluwarsa.

Mengembalikan enumerator untuk koleksi.

IList.Add(Object)
Kedaluwarsa.

DataGridTableStyle Menambahkan ke koleksi ini.

IList.Clear()
Kedaluwarsa.

Menghapus koleksi.

IList.Contains(Object)
Kedaluwarsa.

Menentukan apakah elemen berada dalam koleksi.

IList.IndexOf(Object)
Kedaluwarsa.

Mengembalikan indeks berbasis nol dari kemunculan pertama objek yang ditentukan dalam koleksi.

IList.Insert(Int32, Object)
Kedaluwarsa.

Insert(Int32, Object) Menerapkan metode . Selalu melempar .NotSupportedException

IList.IsFixedSize
Kedaluwarsa.

Mendapatkan nilai yang menunjukkan apakah koleksi memiliki ukuran tetap.

IList.IsReadOnly
Kedaluwarsa.

Mendapatkan nilai yang menunjukkan apakah koleksi bersifat baca-saja.

IList.Item[Int32]
Kedaluwarsa.

Mendapatkan atau mengatur elemen pada indeks yang ditentukan.

IList.Remove(Object)
Kedaluwarsa.

DataGridTableStyleMenghapus .

IList.RemoveAt(Int32)
Kedaluwarsa.

DataGridColumnStyle Menghapus dengan indeks yang ditentukan dari koleksi.

Metode Ekstensi

Nama Deskripsi
AsParallel(IEnumerable)
Kedaluwarsa.

Mengaktifkan paralelisasi kueri.

AsQueryable(IEnumerable)
Kedaluwarsa.

Mengonversi IEnumerable menjadi IQueryable.

Cast<TResult>(IEnumerable)
Kedaluwarsa.

Melemparkan elemen IEnumerable ke jenis yang ditentukan.

OfType<TResult>(IEnumerable)
Kedaluwarsa.

Memfilter elemen IEnumerable berdasarkan jenis tertentu.

Berlaku untuk

Lihat juga