110,529
社区成员
发帖
与我相关
我的任务
分享
/// <summary>
/// 初始化实时DataGridViewX
/// </summary>
public void LoadFmMainRealTime(DataGridViewX dLvRealTime)
{
//
// 初始化列
//
DataGridViewTextBoxColumn column1 = new DataGridViewTextBoxColumn();
DataGridViewTextBoxColumn column2 = new DataGridViewTextBoxColumn();
DataGridViewButtonXColumn column3 = new DataGridViewButtonXColumn();
DataGridViewTextBoxColumn column4 = new DataGridViewTextBoxColumn();
column1.Width = 100;
column1.DataPropertyName = "bh";
column1.HeaderText = "编号";
column2.Width = 150;
column2.DataPropertyName = "zxshk";
column2.HeaderText = "执行时刻";
column3.Width = 250;
column3.HeaderText = "描述";
column3.DataPropertyName = "msh";
column4.Width = 524;
column4.Name = "info";
column4.DataPropertyName = "xx";
column4.HeaderText = "信息";
dLvRealTime.Columns.AddRange(new DataGridViewColumn[] { column1, column2, column3, column4 });
Rectangle ScreenArea = System.Windows.Forms.Screen.GetWorkingArea(dLvRealTime);
dLvRealTime.Columns["info"].Width = ScreenArea.Width - 570;
//
// 初始化数据
//
table = new DataTable("DemoTable");
table.Columns.Add(new DataColumn("bh") { DataType = System.Type.GetType("System.Int32") });
table.Columns.Add(new DataColumn("zxshk"));
table.Columns.Add(new DataColumn("msh"));
table.Columns.Add(new DataColumn("xx"));
for (int i = 0; i < 11; i++)
{
row = table.NewRow();
row[0] = i + 1;
row[1] = DateTime.Now.AddDays(i).ToString("yyy-MM-dd hh:mm:ss.fff");
if (i % 2 != 0)
row[2] = "莱昂纳多进入";
else if (i % 2 == 0)
row[2] = "莱昂纳多出去";
row[3] = "刷卡验证";
table.Rows.Add(row);
}
dataSet.Tables.Add(table);
bindingSource.DataMember = "DemoTable";
DataGridViewButtonXColumn bcx = dLvRealTime.Columns[2] as DataGridViewButtonXColumn;
if (bcx != null)
{
bcx.UseColumnTextForButtonValue = false;
bcx.BeforeCellPaint += Demo_BeforeCellPaint;
}
}
private void Demo_BeforeCellPaint(object sender, BeforeCellPaintEventArgs e)
{
DataGridViewButtonXColumn bcx = sender as DataGridViewButtonXColumn;
if (bcx != null)
{
if (bcx.Text == "莱昂纳多进入")
bcx.Image = new Bitmap(Application.StartupPath + @"\Images\arrow_down.gif");
else if (bcx.Text == "莱昂纳多出去")
bcx.Image = new Bitmap(Application.StartupPath + @"\Images\arrow_up.gif");
}
}