这是我用来设置列样式的代码...但它仅适用于 windows CE5 但是当我在最新的 Mobile Psion Omnii Xt15 上使用它时,宽度将被忽略,并且每列仅显示约 20 像素,都被压扁了。
这是我用来绑定网格的 DataTable..
/// <summary>
///Represents the strongly named DataTable class.
///</summary>
[global::System.Xml.Serialization.XmlSchemaProviderAttribute("GetTypedTableSchema")]
public partial class ContainersDataTable : global::System.Data.DataTable, global::System.Collections.IEnumerable {
private global::System.Data.DataColumn columnContainer_ID;
private global::System.Data.DataColumn columnScanValue;
private global::System.Data.DataColumn columnLkContainerType_ID;
private global::System.Data.DataColumn columnParentContainer_ID;
private global::System.Data.DataColumn columnQuantity;
private global::System.Data.DataColumn columnContainerType_Text;
private global::System.Data.DataColumn columnScanValueDisplay;
private global::System.Data.DataColumn columnGenComment;
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
public ContainersDataTable() {
this.TableName = "Containers";
this.BeginInit();
this.InitClass();
this.EndInit();
}
这是我用来设置列样式的代码...
private void InitializeContainerGrid()
{
DataGridTableStyle ts = new DataGridTableStyle {MappingName = "Containers"};
// container type
DataGridColumnStyle unitCol = new DataGridTextBoxColumn
{
MappingName = ContainerType_Text,
HeaderText = "Unit",
Width = 50
};
ts.GridColumnStyles.Add(unitCol);
// scan value
DataGridColumnStyle scanValueCol = new DataGridTextBoxColumn
{
MappingName = "ScanValueDisplay",
HeaderText = "Scan Value",
Width = 110
};
ts.GridColumnStyles.Add(scanValueCol);
// number of fruit
DataGridColumnStyle fruitNoCol = new DataGridTextBoxColumn
{
MappingName = Quantity,
HeaderText = "Fruit",
Width = 50
};
ts.GridColumnStyles.Add(fruitNoCol);
containerGrid.TableStyles.Add(ts);
}