用ListView实现任务管理器的效果
我通过下面代码实现了ListView分两列的效果,但是选中某行的时候,只有第1列被选中,我想像windows任务管理器一样,选中某行的时候是整行的每列都被选中,应该怎么写?
ListView listView = new ListView();
listView.Dock = DockStyle.Fill;
listView.View = View.Details;
listView.Sorting = SortOrder.Ascending;
ColumnHeader header1 = new ColumnHeader();
header1.Text = "Title ";
ColumnHeader header2 = new ColumnHeader();
header2.Text = "Author ";
listView.Columns.AddRange(new ColumnHeader[] { header1, header2 });
ListViewItem item1 = new ListViewItem(new string[] { "C++ Program ", "Singel " });
ListViewItem item2 = new ListViewItem(new string[] { "C# Program ", "Lee " });
listView.Items.AddRange(new ListViewItem[] { item1, item2 });
this.Controls.Add(listView);
this.Size = new System.Drawing.Size(550, 330);
------解决方案--------------------代码:
ListView.FullRowSelect = true;
也可在图形界面下,直接设置此属性为true