c# - 其项目c#中所有子项目的可点击 ListView

标签 c# listview click

我正在制作许多列的 ListView ,我想让列表在所有子项中都可以点击,如下图所示。

enter image description here

但是,我得到的结果如下图所示。

enter image description here

这是我的代码:

    private void button6_Click(object sender, EventArgs e)
        {
            ListViewItem listviewitem;

            listviewitem = new ListViewItem("John");
            listviewitem.SubItems.Add("Smith");
            listviewitem.SubItems.Add("kaya");
            listviewitem.SubItems.Add("bun");
            this.listView1.Items.Add(listviewitem);
            this.listView1.ColumnClick += new ColumnClickEventHandler(ColumnClick);
//show header
            listView1.View = View.Details;

            // Loop through and size each column header to fit the column header text.
            foreach (ColumnHeader ch in this.listView1.Columns)
            {
                ch.Width = -2;
            }
}

这是我的 columnclick 事件处理程序。

 // ColumnClick event handler.
    private void ColumnClick(object o, ColumnClickEventArgs e)
    {
        // Set the ListViewItemSorter property to a new ListViewItemComparer 
        // object. Setting this property immediately sorts the 
        // ListView using the ListViewItemComparer object.
        this.listView1.ListViewItemSorter = new ListViewItemComparer(e.Column);
    }




    }
class ListViewItemComparer : IComparer
{
    private int col;
    public ListViewItemComparer()
    {
        col = 0;
    }
    public ListViewItemComparer(int column)
    {
        col = column;
    }
    public int Compare(object x, object y)
    {
        return String.Compare(((ListViewItem)x).SubItems[col].Text, ((ListViewItem)y).SubItems[col].Text);
    }
}

最佳答案

 listView1.FullRowSelect = true;

关于c# - 其项目c#中所有子项目的可点击 ListView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11894586/

相关文章:

android - 在appium中查找 ListView 中的所有元素

javascript - jQuery 闭包 : How to get a value from a function click

c# - Entity Framework 、DBContext 和 using() + 异步?

C# 将希伯来历日期转换为公历日期

c# - 从 PipeReader 读取超时

javascript - jQuery 函数在 append() 之后没有响应

javascript - 在所有元素上应用 jquery 代码

c# - 将多个对象从 Angular Controller 发布到 Web API 2

java - 如何保持列表项和数据库行之间的连接?

Android:在 ListView 中对整数值进行排序