C#发现之旅:C#开发Windows Service程序(上)
2009-04-06 08:24:20 来源:WEB开发网对于工具条的“刷新列表”按钮,其点击事件处理为
private void btnRefresh_Click(object sender, EventArgs e)
{
this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
lvwRecord.BeginUpdate();
try
{
lvwRecord.Items.Clear();
using (System.Data.IDbCommand cmd = Util.DBConnection.CreateCommand())
{
cmd.CommandText = "Select RecordID , ObjectName , WatchTime , EventStyle From FileSystemLog order by WatchTime";
System.Data.IDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
ListViewItem NewItem = new ListViewItem();
NewItem.Tag = Convert.ToString(reader.GetValue(0));
NewItem.Text = Convert.ToString(reader.GetValue(1));
NewItem.SubItems.Add(Convert.ToString(reader.GetValue(2)));
string Style = Convert.ToString(reader.GetValue(3));
NewItem.SubItems.Add(Style);
Style = Style.Trim().ToLower();
if (Style == "created")
{
NewItem.Group = lvwRecord.Groups[0];
NewItem.ImageIndex = 0;
}
else if (Style == "changed")
{
NewItem.Group = lvwRecord.Groups[1];
NewItem.ImageIndex = 1;
}
else if (Style == "deleted")
{
NewItem.Group = lvwRecord.Groups[2];
NewItem.ImageIndex = 2;
}
else if (Style == "renamed")
{
NewItem.Group = lvwRecord.Groups[3];
NewItem.ImageIndex = 3;
}
NewItem.StateImageIndex = NewItem.ImageIndex;
lvwRecord.Items.Add(NewItem);
}
reader.Close();
}
myStatus.Text = "共列出 " + lvwRecord.Items.Count + " 个记录";
}
catch (Exception ext)
{
MessageBox.Show(ext.ToString(), "系统错误");
}
this.Cursor = System.Windows.Forms.Cursors.Default;
lvwRecord.EndUpdate();
}
- ››开发Android 日历教程
- ››开发学院总结 Win 8实用技巧大全
- ››开发学院原创教程:把win8的IE10放桌面上方法(非...
- ››开发者眼中的Windows Phone和Android
- ››开发学院教你用SQL 语句最快速清空MySQL 数据表的...
- ››发现数据库对象的依赖关系
- ››开发一个自己的HTML在线编辑器(一)
- ››开发一个自己的HTML在线编辑器(二)
- ››开发者在App Store上赚的钱比在Android Market上多...
- ››开发者应深入学习的10个Android开源应用项目
- ››开发移动 Web Ajax 应用
- ››开发者眼中的iPhone与Android
更多精彩
赞助商链接