GridTableStylesCollection Kelas

Definisi

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)>]
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 untuk 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 . Sebaliknya, DataGrid menampilkan setiap tabel menggunakan pengaturan default untuk warna, lebar, dan pemformatan. Semua kolom dari 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 apa punTableName, 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

Count

Mendapatkan jumlah total elemen dalam koleksi.

(Diperoleh dari BaseCollection)
IsReadOnly

Mendapatkan nilai yang menunjukkan apakah koleksi bersifat baca-saja.

(Diperoleh dari BaseCollection)
IsSynchronized

Mendapatkan nilai yang menunjukkan apakah akses ke disinkronkan ICollection .

(Diperoleh dari BaseCollection)
Item[Int32]

Mendapatkan yang DataGridTableStyle ditentukan oleh indeks.

Item[String]

DataGridTableStyle Mendapatkan dengan nama yang ditentukan.

List

Mendapatkan daftar yang mendasar.

SyncRoot

Mendapatkan objek yang dapat digunakan untuk menyinkronkan akses ke BaseCollection.

(Diperoleh dari BaseCollection)

Metode

Add(DataGridTableStyle)

DataGridTableStyle Menambahkan ke koleksi ini.

AddRange(DataGridTableStyle[])

Menambahkan array gaya tabel ke koleksi.

Clear()

Menghapus koleksi.

Contains(DataGridTableStyle)

Mendapatkan nilai yang menunjukkan apakah GridTableStylesCollection berisi yang ditentukan DataGridTableStyle.

Contains(String)

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

CopyTo(Array, Int32)

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)

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)

Menentukan apakah objek yang ditentukan sama dengan objek saat ini.

(Diperoleh dari Object)
GetEnumerator()

Mendapatkan objek yang memungkinkan iterasi melalui anggota koleksi.

(Diperoleh dari BaseCollection)
GetHashCode()

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

Mendapatkan dari instans Type saat ini.

(Diperoleh dari Object)
InitializeLifetimeService()
Kedaluwarsa.

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

(Diperoleh dari MarshalByRefObject)
MemberwiseClone()

Membuat salinan dangkal dari saat ini Object.

(Diperoleh dari Object)
MemberwiseClone(Boolean)

Membuat salinan dangkal objek saat ini MarshalByRefObject .

(Diperoleh dari MarshalByRefObject)
OnCollectionChanged(CollectionChangeEventArgs)

Memunculkan kejadian CollectionChanged.

Remove(DataGridTableStyle)

Menghapus yang ditentukan DataGridTableStyle.

RemoveAt(Int32)

DataGridTableStyle Menghapus pada indeks yang ditentukan.

ToString()

Mengembalikan string yang mewakili objek saat ini.

(Diperoleh dari Object)

Acara

CollectionChanged

Terjadi ketika koleksi telah berubah.

Implementasi Antarmuka Eksplisit

ICollection.CopyTo(Array, Int32)

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

ICollection.Count

Mendapatkan jumlah item dalam koleksi.

ICollection.IsSynchronized

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

ICollection.SyncRoot

Mendapatkan objek yang dapat digunakan untuk menyinkronkan akses ke koleksi.

IEnumerable.GetEnumerator()

Mengembalikan enumerator untuk koleksi.

IList.Add(Object)

DataGridTableStyle Menambahkan ke koleksi ini.

IList.Clear()

Menghapus koleksi.

IList.Contains(Object)

Menentukan apakah elemen berada dalam koleksi.

IList.IndexOf(Object)

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

IList.Insert(Int32, Object)

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

IList.IsFixedSize

Mendapatkan nilai yang menunjukkan apakah koleksi memiliki ukuran tetap.

IList.IsReadOnly

Mendapatkan nilai yang menunjukkan apakah koleksi bersifat baca-saja.

IList.Item[Int32]

Mendapatkan atau mengatur elemen pada indeks yang ditentukan.

IList.Remove(Object)

Menghapus yang ditentukan DataGridTableStyle.

IList.RemoveAt(Int32)

DataGridColumnStyle Menghapus dengan indeks yang ditentukan dari koleksi.

Metode Ekstensi

Cast<TResult>(IEnumerable)

Mentransmisikan elemen dari ke IEnumerable jenis yang ditentukan.

OfType<TResult>(IEnumerable)

Memfilter elemen berdasarkan IEnumerable jenis yang ditentukan.

AsParallel(IEnumerable)

Mengaktifkan paralelisasi kueri.

AsQueryable(IEnumerable)

Mengonversi menjadi IEnumerableIQueryable.

Berlaku untuk

Lihat juga