listview控件:怎么选中某一行的子项
如何实现:点击我想要的内容时(如某一行的子项),该子项变成选中状态。
------解决方案--------------------
private void listView1_MouseUp(object sender, MouseEventArgs e)
{
ListView _ListView = (ListView)sender;
ListViewItem _Item = _ListView.GetItemAt(5, e.Y);
if (_Item != null)
{
ListViewItem.ListViewSubItem _SubItem = _Item.GetSubItemAt(e.X, 5);
if (_SubItem != null)
{
Control _SetLabel = _ListView.Controls["SelectLab"];
if (_SetLabel == null)
{
_SetLabel = new Label();
_SetLabel.Name = "SelectLab";
_SetLabel.AutoSize = false;
_SetLabel.BackColor = Color.Yellow;
_SetLabel.ForeColor = Color.Red;
_SetLabel.Font = _ListView.Font;
_ListView.Controls.Add(_SetLabel);
}
_SetLabel.Text = _SubItem.Text;
_SetLabel.Location = new Point(_SubItem.Bounds.X, _SubItem.Bounds.Y);
if (_SubItem.Equals(_Item.SubItems[0]))
{
_SetLabel.Size = new Size(_ListView.Columns[0].Width, _SubItem.Bounds.Height);
}
else
{
_SetLabel.Size = new Size(_SubItem.Bounds.Width, _SubItem.Bounds.Height);
}
}
}
}
加个这个看看是不是你要的效果