HoverItem 在 ListView 中返回 null [英] HoverItem returing null in ListView

查看:29
本文介绍了HoverItem 在 ListView 中返回 null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在为 listview 编写自定义控件期间:我像这样覆盖这个方法:

During writing a custom control for listview: I am overriding this method like this:

protected override void OnDragDrop(DragEventArgs drgevent)
{
    base.OnDragDrop(drgevent);

    // get the currently hovered row that the items will be dragged to
    Point clientPoint = base.PointToClient(new Point(drgevent.X, drgevent.Y));
    ListViewItem hoverItem = base.GetItemAt(clientPoint.X, clientPoint.Y);

有时 hoverItem 变为 null :( 当我将项目放置在列表视图的最右侧区域时它变为 null...如果我将它放置在列表中的某个位置,其中有项目和文本,它可以正常工作,如果我把它放在没有文字的地方,那么它就变成空了....

Sometimes hoverItem becomes null :( It becomes null when I am dropping the item at the far right area of the listview...If I drop it somewhere in the list that there are items and text in there, it works fine, if I drop it at somewhere that items don't have text, then it becomes null....

为了更清晰,我附上了一张图片

I am attaching a picture for more clarity

有什么问题?或者您认为有更好的方法可以做到这一点?

What is the problem? or do you think there are better ways for doing this?

推荐答案

没有问题.这是设计使然.没有红点所在的项目.ListView 具有不同的视图模式(View 属性),其中可以有包含每个项目的图标/文本块",也可以有多个项目列.

There is no problem. This is by design. There is no item where the red dot is. ListView has different view modes (View property) where there can be icon/text "blocks" that enclose each item, or there can be multiple columns of items.

我认为将 View 属性设置为 View.Details 并将 FullRowSelect 设置为 true,GetItemAt 会在每一行的末尾点击空格,但我必须尝试确定.

I think that setting the View property to View.Details and setting FullRowSelect to true, GetItemAt will hit on the whitespace to the end for each row, but I'd have to try it to be sure.

这篇关于HoverItem 在 ListView 中返回 null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆