listview相关知识

来源:互联网 发布:js闭包实际开发用途 编辑:程序博客网 时间:2024/05/16 05:26

1.根据名称key找到到对应的索引 并且选中指定行并对其设置背景色

 string selecttext = myTable.Rows[0][0].ToString().Trim() + " [" + myTable.Rows[0][1].ToString().Trim() + "]";
            int selectindex = 0;
            foreach (ListViewItem eachItem in this.lvDoor.Items)
            {
                if (eachItem.Text == selecttext)
                {
                    selectindex = eachItem.Index;
                }
            }
            lvDoor.Items[selectindex].Selected = true;
            lvDoor.Items[selectindex].Checked = true;
            for (int i = 0; i < lvDoor.Items.Count; i++)
            {
                if (lvDoor.Items[i].BackColor == Color.RoyalBlue)
                {
                    lvDoor.Items[i].BackColor = Color.Azure;
                }
            }
            lvDoor.Items[selectindex].BackColor = Color.RoyalBlue;

 

2.填充listview

                ListViewItem rdInfo = new ListViewItem("");
                rdInfo.SubItems.Add("");
                rdInfo.SubItems.Add("");
                rdInfo.SubItems.Add(card_no);
                rdInfo.SubItems.Add("");
                rdInfo.SubItems.Add("");
                rdInfo.SubItems.Add("");
                rdInfo.SubItems.Add(time);
                rdInfo.SubItems.Add("");
                this.lvRunInfo.Items.Add(rdInfo);

 

3.调整listview的宽度和高度

 ImageList imageList = new ImageList();   //设置行高20
            imageList.ImageSize = new System.Drawing.Size(1, 20);   //分别是宽和高
            lvDevInfo.SmallImageList = imageList;