Pocket PC 中 DataGrid 的用法

本文介绍了如何使用DataTable作为PocketPC中DataGrid的数据源,并提供了设置DataGrid标题样式的代码示例。

在 Pocket PC 中 DataGrid 省去了很多功能!

列如不能在 DataGrid 中添加控件

下面方法用 DataTable 作为 DataGrid 的数据源:

Code
private void DataGridSource()
{
LogDal logdal
= new LogDal();
List
<LogEntity> logs = logdal.select();

DataSet ds
= new DataSet();

DataTable dt
= new DataTable();
dt.Columns.Add(
"id", typeof(Int32));
dt.Columns.Add(
"context", typeof(string));
dt.Columns.Add(
"logTime", typeof(DateTime));

foreach (LogEntity logentity in logs)
{
DataRow dr
= dt.NewRow();
dr[
"id"] = logentity.Id;
dr[
"context"] = logentity.Context;
dr[
"logTime"] = logentity.LogTime;

dt.Rows.Add(dr);

}
ds.Tables.Add(dt);

this.dataGrid1.DataSource = ds.Tables[0];
}

 

然后可以对 DataGrid 的标题设置样式,当然这个也可以在属性管理器中进行设置。

Code
     DataGridTableStyle ts = new DataGridTableStyle();
ts.MappingName
= ds.Tables[0].ToString();

DataGridColumnStyle dgcsId
= new DataGridTextBoxColumn();
dgcsId.MappingName
= ds.Tables[0].Columns["id"].ToString();
dgcsId.HeaderText
= "ID";
ts.GridColumnStyles.Add(dgcsId);

DataGridColumnStyle DgcsContext
= new DataGridTextBoxColumn();
DgcsContext.MappingName
= ds.Tables[0].Columns["context"].ToString();
DgcsContext.HeaderText
= "内容";
ts.GridColumnStyles.Add(DgcsContext);

DataGridColumnStyle dgcsTime
= new DataGridTextBoxColumn();
dgcsTime.MappingName
= ds.Tables[0].Columns["logTime"].ToString();
dgcsTime.HeaderText
= "时间";
ts.GridColumnStyles.Add(dgcsTime);

this.dataGrid1.TableStyles.Add(ts);

 

转载于:https://www.cnblogs.com/yongbo/archive/2008/10/14/1310590.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值