为 Win CE 设备自定义 DataGrid

Customize DataGrid for Win CE Device

我正在写一个windowsce的应用程序,所以我必须使用VS 2008。

我在 dataGrid-Control 中显示一些数据(DataGridView 不可用!),我想对其进行自定义。

诸如 grid.Columns[i].width 等的东西在这些控件上不起作用。

我需要更改列宽和 header 文本,我该如何实现? 数据网格在运行时使用此行获取条目:

dgLatestPositions.DataSource = items;

items 是一个包含 objects 的列表<>,table 有 2 列。 dataGrid 的视图工作正常,除了这些问题。

编辑:也许是这样的? (它也没有工作)

DataGridTableStyle t = new DataGridTableStyle();
t.GridColumnStyles[0].HeaderText = "Coding";
t.GridColumnStyles[1].HeaderText = "Amount";
dgLatestPositions.TableStyles.Add(t);

编辑:

所有项目都包含在一个列表中。 article-objects 看起来是这样的: public class lastChanges

{
    public long coding { get; set; }
    public int amount { get; set; }
}

Table 显示如下(示例)

编码 |数量

0123456789|3

0829346128|4

我需要做的是调整第一列的大小并更改标题

我们也有一个应用程序需要在WindowsCE下支持并且必须在VS2008中完成。你非常接近,我们所做的是创建一个 base-class 数据网格用于显示,并添加了一种方法来添加我们想要的列,获取标题文本、绑定列源和宽度。这是我们的方法,"myTblStyle" 是您的 DataGridTableStyle "t" 变量。

public void AddColumn(string hdr, string colName, int colWidth)
{
    DataGridTextBoxColumn tbc = new DataGridTextBoxColumn();
    tbc.HeaderText = hdr;
    tbc.MappingName = colName;
    tbc.Width = colWidth;
    myTblStyle.GridColumnStyles.Add(tbc);
}