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

  • Thread starter Thread starter TheSteph
  • Start date Start date
T

TheSteph

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.
 
int i = 0;

foreach(ListViewItem myView in this.lvBody.Items)
{
if(this.lvBody.Items.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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top