WEB开发网
开发学院软件开发C语言 C#发现之旅:C#开发Windows Service程序(上) 阅读

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.WaitCurs

对于工具条的“刷新列表”按钮,其点击事件处理为

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

上一页  5 6 7 8 9 10 

Tags:发现 之旅 开发

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接