- 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];
- }
- 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);