By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,331 Members | 1,278 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,331 IT Pros & Developers. It's quick & easy.

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

P: n/a


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.
May 17 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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" <Th******@NoSpam.com> wrote in message
news:uw**************@TK2MSFTNGP03.phx.gbl...


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.

May 17 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.