public void Main_Load(object sender, EventArgs e)//初始化加载
        {
            sql = new SqlHelp("data source=mydb.db");
            sql.CreateTable("tongxunlu", new string[] { "Name", "Phone", "Groups", "Email", "QQ", "Weixin", "Info" }, new string[] { "TEXT", "TEXT", "TEXT", "TEXT", "TEXT", "TEXT", "TEXT" });
            //读取整张表
            SQLiteDataReader reader = sql.ReadFullTable("tongxunlu");

            this.ListView.BeginUpdate();   //数据更新,UI暂时挂起,直到EndUpdate绘制控件,可以有效避免闪烁并大大提高加载速度
            while (reader.Read())
            {
                ListViewItem lvi = new ListViewItem();
                lvi.Text = reader.GetString(reader.GetOrdinal("Name"));
                lvi.SubItems.Add(reader.GetString(reader.GetOrdinal("Phone")));
                lvi.SubItems.Add(reader.GetString(reader.GetOrdinal("Groups")));
                lvi.SubItems.Add(reader.GetString(reader.GetOrdinal("Email")));
                lvi.SubItems.Add(reader.GetString(reader.GetOrdinal("QQ")));
                lvi.SubItems.Add(reader.GetString(reader.GetOrdinal("Weixin")));
                lvi.SubItems.Add(reader.GetString(reader.GetOrdinal("Info")));
                this.ListView.Items.Add(lvi);
            }
            this.ListView.EndUpdate();  //结束数据处理,UI界面一次性绘制。 sql.CloseConnection();
            sql.CloseConnection();
            ImageList imgList = new ImageList();

            imgList.ImageSize       = new Size(1, 35);//分别是宽和高
            ListView.SmallImageList = imgList;
        }
Esempio n. 2
0
 private void NewOK_Click(object sender, EventArgs e)
 {
     if (NewContent.Text != "")
     {
         sql = new SqlHelp("data source=mydb.db");
         sql.CreateTable("fenzu", new string[] { "Name" }, new string[] { "TEXT" });
         sql.InsertValues("fenzu", new string[] { NewContent.Text });
         sql.CloseConnection();
         MessageBox.Show("添加成功!");
         this.DialogResult = DialogResult.OK;
         this.Close();
     }
     else
     {
         MessageBox.Show("分组名称不能为空!");
     }
 }