C# ListView
ListView失去焦点选中行不能高亮显示的问题
ListView的HideSelection属性设置为True。
1 public Form1() 2 { 3 InitializeComponent(); 4 5 //显示样式 6 listView1.View = View.LargeIcon; 7 listView1.LargeImageList = imageList1; 8 9 //禁止多选 10 listView1.MultiSelect = false; 11 12 //添加项 13 listView1.Items.Add("aaaaaa"); 14 listView1.Items.Add("BBBBBBB"); 15 16 listView1.Items[0].ImageIndex = 0; 17 listView1.Items[1].ImageIndex = 0; 18 19 } 20 21 private void Form1_Load(object sender, EventArgs e) 22 { 23 //选中一项 24 listView1.Items[1].Selected = true; 25 listView1.Items[0].EnsureVisible(); 26 listView1.Select(); //激活控件 27 28 29 } 30 31 private void button1_Click(object sender, EventArgs e) 32 { 33 string str = listView1.SelectedItems[0].Text; 34 35 MessageBox.Show(str); 36 } 37 38 39 40 private void listView1_Click(object sender, EventArgs e) 41 { 42 string str = listView1.SelectedItems[0].Text; 43 44 MessageBox.Show(str); 45 46 }