GridTableStylesCollection 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
注意
DataGrid is provided for binary compatibility with .NET Framework and is not intended to be used directly from your code. Use DataGridView instead.
表示控件中DataGridTableStyle对象的集合DataGrid。
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
- 继承
- 属性
- 实现
示例
下面的代码示例创建两个DataGridTableStyle对象,并将每个对象添加到GridTableStylesCollection控件的属性返回TableStyles。DataGrid
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
注解
包含允许DataGridTableStyle控件显示每个DataTable控件的DataSet自定义网格样式的对象DataGrid。GridTableStylesCollection
在控件上DataGrid,该TableStyles属性返回 .GridTableStylesCollection
默认情况下, GridTableStylesCollection 不包含任何 DataGridTableStyle 对象。 DataGrid而是使用颜色、宽度和格式设置的默认设置显示每个表。 将显示每个表的所有列。 将 a DataGridTableStyle 添加到集合时,使用该DataGridMappingName对象来确定哪个对象为网格提供数据。 例如,如果数据源包含三DataTable个DataSet对象,则必须MappingName匹配TableName其中一个对象。 如果值 MappingName 与任何 TableName 值不匹配,则默认设置将用于显示每个表的数据,并且 DataGridTableStyle 将忽略这些设置。
注意
始终创建 DataGridColumnStyle 对象并将其添加到 GridColumnStylesCollection 将对象添加到 DataGridTableStyle 之前 GridTableStylesCollection。 向集合中添加具有有效MappingName值的空DataGridTableStyle时,DataGridColumnStyle会自动为你生成对象。 因此,如果尝试将具有重复
属性
| 名称 | 说明 |
|---|---|
| Count |
已过时.
获取集合中的元素总数。 (继承自 BaseCollection) |
| IsReadOnly |
已过时.
获取一个值,该值指示集合是否为只读。 (继承自 BaseCollection) |
| IsSynchronized |
已过时.
获取一个值,该值指示是否同步对 ICollection 数据的访问。 (继承自 BaseCollection) |
| Item[Int32] |
已过时.
DataGridTableStyle获取索引指定的值。 |
| Item[String] |
已过时.
获取 |
| List |
已过时.
获取基础列表。 |
| List |
已过时.
获取实例中包含的 BaseCollection 元素列表。 (继承自 BaseCollection) |
| SyncRoot |
已过时.
获取可用于同步对 . BaseCollection的访问的对象。 (继承自 BaseCollection) |
方法
活动
| 名称 | 说明 |
|---|---|
| CollectionChanged |
已过时.
在集合发生更改时发生。 |
显式接口实现
| 名称 | 说明 |
|---|---|
| ICollection.CopyTo(Array, Int32) |
已过时.
将集合复制到兼容的一维 Array,从目标数组的指定索引处开始。 |
| ICollection.Count |
已过时.
获取集合中项的数目。 |
| ICollection.IsSynchronized |
已过时.
获取一个值,该值指示对 GridTableStylesCollection 同步的访问是否同步(线程安全)。 |
| ICollection.SyncRoot |
已过时.
获取一个对象,该对象可用于同步对集合的访问。 |
| IEnumerable.GetEnumerator() |
已过时.
返回集合的枚举器。 |
| IList.Add(Object) |
已过时.
将 a DataGridTableStyle 添加到此集合。 |
| IList.Clear() |
已过时.
清除集合。 |
| IList.Contains(Object) |
已过时.
确定元素是否在集合中。 |
| IList.IndexOf(Object) |
已过时.
返回集合中指定对象的第一个匹配项的从零开始的索引。 |
| IList.Insert(Int32, Object) |
已过时.
Insert(Int32, Object)实现该方法。 总是引发 NotSupportedException。 |
| IList.IsFixedSize |
已过时.
获取一个值,该值指示集合是否具有固定大小。 |
| IList.IsReadOnly |
已过时.
获取一个值,该值指示集合是否为只读。 |
| IList.Item[Int32] |
已过时.
获取或设置指定索引处的元素。 |
| IList.Remove(Object) |
已过时.
删除指定的 DataGridTableStyle。 |
| IList.RemoveAt(Int32) |
已过时.
从 DataGridColumnStyle 集合中删除具有指定索引的索引。 |
扩展方法
| 名称 | 说明 |
|---|---|
| AsParallel(IEnumerable) |
已过时.
启用查询的并行化。 |
| AsQueryable(IEnumerable) |
已过时.
将 IEnumerable 转换为 IQueryable。 |
| Cast<TResult>(IEnumerable) |
已过时.
将 IEnumerable 的元素强制转换为指定类型。 |
| OfType<TResult>(IEnumerable) |
已过时.
根据指定类型筛选 IEnumerable 的元素。 |