PC Review


Reply
Thread Tools Rate Thread

Any better way to find the Clicked SubItem in a ListView ?

 
 
TheSteph
Guest
Posts: n/a
 
      17th May 2006


Any way to find the Clicked SubItem in a ListView ?

private int GetSubItemAtPos(ListView AListView, Point APoint)
{
int PositionCounter = 0;
int TmpRelativeColIndex = -1;
//Browse All Column by DISPLAYED INDEX
for (int ColDisplayCount = 0; ColDisplayCount < AListView.Columns.Count;
ColDisplayCount++)
{
//Find ColumnIndex relative to the current ColDisplayCount
TmpRelativeColIndex = -1;
for (int ColIndexCount = 0; ColIndexCount < AListView.Columns.Count;
ColIndexCount++)
{
if (AListView.Columns[ColIndexCount].DisplayIndex ==
ColDisplayCount)
{
TmpRelativeColIndex = ColIndexCount;
break;
}
}
//if a TmpRelativeColIndex has been found, check if X pos is now
inside new bounds
if (TmpRelativeColIndex > -1)
{
//Incremental end position
PositionCounter +=
AListView.Columns[TmpRelativeColIndex].Width;
//chec if X pos is inside bounds
if (APoint.X < PositionCounter) return TmpRelativeColIndex;
}
}
return -1;
}

steph.


 
Reply With Quote
 
 
 
 
MikeY
Guest
Posts: n/a
 
      17th May 2006
int i = 0;

foreach(ListViewItem myView in this.lvBody.Items)
{
if(this.lvBody.Items[i].Selected == true)
{
DoSomething;
}
}


But you can interchange lvBody with myView with the syntax
myView.ListViewItem and treat it as normal

Hope that helps a bit

MikeY
"TheSteph" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
>
> Any way to find the Clicked SubItem in a ListView ?
>
> private int GetSubItemAtPos(ListView AListView, Point APoint)
> {
> int PositionCounter = 0;
> int TmpRelativeColIndex = -1;
> //Browse All Column by DISPLAYED INDEX
> for (int ColDisplayCount = 0; ColDisplayCount < AListView.Columns.Count;
> ColDisplayCount++)
> {
> //Find ColumnIndex relative to the current ColDisplayCount
> TmpRelativeColIndex = -1;
> for (int ColIndexCount = 0; ColIndexCount <
> AListView.Columns.Count;
> ColIndexCount++)
> {
> if (AListView.Columns[ColIndexCount].DisplayIndex ==
> ColDisplayCount)
> {
> TmpRelativeColIndex = ColIndexCount;
> break;
> }
> }
> //if a TmpRelativeColIndex has been found, check if X pos is now
> inside new bounds
> if (TmpRelativeColIndex > -1)
> {
> //Incremental end position
> PositionCounter +=
> AListView.Columns[TmpRelativeColIndex].Width;
> //chec if X pos is inside bounds
> if (APoint.X < PositionCounter) return TmpRelativeColIndex;
> }
> }
> return -1;
> }
>
> steph.
>
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Determine subitem clicked in listview =?Utf-8?B?SC5CLg==?= Microsoft VC .NET 2 12th Oct 2005 06:28 PM
listview subitem Jano Microsoft VC .NET 6 5th May 2004 08:00 AM
ListView: How can I tell which subitem is clicked? Peter Steele Microsoft C# .NET 2 17th Feb 2004 06:06 AM
SAMPLE: Get ndex of Item/SubItem clicked in a ListView Alex Yakhnin [MVP] Microsoft Dot NET Compact Framework 1 29th Oct 2003 01:02 AM
Find item I double-clicked in ListView and read contents Chris LaJoie Microsoft C# .NET 1 4th Oct 2003 08:15 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:21 PM.