Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何检查鼠标单击位置是否仅位于virtualmode下listview中[0]列中的项目内?_C#_.net_Winforms_Listview - Fatal编程技术网

C# 如何检查鼠标单击位置是否仅位于virtualmode下listview中[0]列中的项目内?

C# 如何检查鼠标单击位置是否仅位于virtualmode下listview中[0]列中的项目内?,c#,.net,winforms,listview,C#,.net,Winforms,Listview,C:如何检查鼠标单击位置是否仅位于virtualmode下listview中[0]列中的项目内 我可以使用ListView.GetItemAt获取鼠标刚刚单击的Item对象,但是在这之后,我如何检查它是否在列[0]中被单击 类似的东西可能在鼠标事件中:e是MouseEventArgs类型: // get the rectangle for the first item; used for getting sideways scrolling offset Rectangle r = listVi

C:如何检查鼠标单击位置是否仅位于virtualmode下listview中[0]列中的项目内


我可以使用ListView.GetItemAt获取鼠标刚刚单击的Item对象,但是在这之后,我如何检查它是否在列[0]中被单击

类似的东西可能在鼠标事件中:e是MouseEventArgs类型:

// get the rectangle for the first item; used for getting sideways scrolling offset
Rectangle r = listView1.GetItemRect(0);
int leftOffset = r.Left;

if (listView1.Columns[0].Width + leftOffset > e.X)
{
    // first column
}
else
{
    // other column
}

更新:错过了第一个有趣的专栏;第一个解决方案是在鼠标下挑出列索引;这只选择第一个或其他情况。请注意,它还考虑了横向滚动。

不管怎样,我在对代码进行了一些修改后找到了一个解决方案。以下是我使用的解决方案:

    private void lvListView_MouseClick(object sender, MouseEventArgs e)
    {
        ListView lv = (ListView)sender;
        ListViewItem lvi;

        if (e.X > lv.Columns[0].Width)
        {
            lvi = null;
        }
        else
        {
            lvi = lv.GetItemAt(e.X, e.Y);
        }

        if (lvi != null)
        {
            lvi.Checked = !lvi.Checked;
            lv.Invalidate(lvi.Bounds);
        }
    }

ListViewItem有一个GetSubItemAt成员,可能会有所帮助