I'm using ListView.GetItemAt(x,y)
to retrieve an item from the ListView
, but I'm not
able to get the item when I set the FullRowSelect
option to false
.
I'm not sure of how to do it in .NET 1.1. Does anyone have any pointers?
Here's a code snippet:
public int GetListViewSubItem(ListView listView1, Point pt)
{
const int LVM_FIRST = 0x1000;
const int LVM_GETSUBITEMRECT = (LVM_FIRST + 56);
const int LVIR_BOUNDS = 0;
RECT myrect;
ListViewItem lvitem = listView1.GetItemAt(pt.X, pt.Y);
if(lvitem == null && listView1.SelectedItems.Count > 0)
lvitem = listView1.SelectedItems[0];
int intLVSubItemIndex = -1;
ListViewItem.ListViewSubItem LVSubItem = null;
if(lvitem != null)
{
int intSendMessage;
for ( int i = 1; i <= lvitem.SubItems.Count - 1; i++)
{
LVSubItem = lvitem.SubItems[i];
myrect = new RECT();
myrect.top = i;
myrect.left = LVIR_BOUNDS;
intSendMessage = SendMessage(listView1.Handle,
LVM_GETSUBITEMRECT,
lvitem.Index, ref myrect);
if (pt.X < myrect.left)
{
LVSubItem = lvitem.SubItems[0];
intLVSubItemIndex = 0;
break;
}
else if (pt.X >= myrect.left & pt.X <= myrect.right)
{
intLVSubItemIndex = i;
break;
}
else
LVSubItem = null;
}
}
if (LVSubItem == null || lvitem == null)
{
intLVSubItemIndex = -1;
}
return intLVSubItemIndex;
}
This method is supposed to show me which cell was clicked.
Tt works, but if I change the fullrowselect
to false
, it returns a null
value.
I even tried getitemat(0,e.y)
, but it didn't work.
whenever I select an item in the ListView
, it highlighted with the color blue, so it is not possible to view what is selected. I'm trying to remove that blue highlight.
Any thoughts?