Pocket PC 中 DataGrid 的用法

来源:互联网 发布:linux搭建.net服务器 编辑:程序博客网 时间:2024/06/05 20:52

 

  1. private void DataGridSource()
  2. {
  3.     LogDal logdal = new LogDal();
  4.     List<LogEntity> logs = logdal.select();
  5.     DataSet ds = new DataSet();
  6.     DataTable dt = new DataTable();
  7.     dt.Columns.Add("id"typeof(Int32));
  8.     dt.Columns.Add("context"typeof(string));
  9.     dt.Columns.Add("logTime"typeof(DateTime));
  10.     foreach (LogEntity logentity in logs)
  11.     {
  12.         DataRow dr = dt.NewRow();
  13.         dr["id"] = logentity.Id;
  14.         dr["context"] = logentity.Context;
  15.         dr["logTime"] = logentity.LogTime;
  16.         dt.Rows.Add(dr);
  17.     }
  18.     ds.Tables.Add(dt);
  19.     this.dataGrid1.DataSource = ds.Tables[0];
  20. }

 

  1. DataGridTableStyle ts = new DataGridTableStyle(); 
  2. ts.MappingName = ds.Tables[0].ToString(); 
  3. DataGridColumnStyle dgcsId = new DataGridTextBoxColumn(); 
  4. dgcsId.MappingName = ds.Tables[0].Columns["id"].ToString(); 
  5. dgcsId.HeaderText = "ID"
  6. ts.GridColumnStyles.Add(dgcsId); 
  7. DataGridColumnStyle DgcsContext = new DataGridTextBoxColumn(); 
  8. DgcsContext.MappingName = ds.Tables[0].Columns["context"].ToString(); 
  9. DgcsContext.HeaderText = "内容"; ts.GridColumnStyles.Add(DgcsContext); 
  10. DataGridColumnStyle dgcsTime = new DataGridTextBoxColumn(); 
  11. dgcsTime.MappingName = ds.Tables[0].Columns["logTime"].ToString(); 
  12. dgcsTime.HeaderText = "时间"
  13. ts.GridColumnStyles.Add(dgcsTime); 
  14. this.dataGrid1.TableStyles.Add(ts);