473,326 Members | 2,076 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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



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
1 2102
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Angel Monson | last post by:
Is there a way I can find out which item I double-clicked inside a listview? And what about with subitems? And once I get an item number, can I use it to read the item and subitem contents? And if...
1
by: andrewcw | last post by:
The clcik event on the ListView control seems to trigger off the item level ( the first column ). I would like to be able to trap the click event on a particular subitem ( a specific column's row...
2
by: Peter Steele | last post by:
I have a form containing a ListView with four columns, creating a multi-cell table. I want to have an event which can determine which cell in the table is under the cursor when a double-click is...
2
by: Paddy | last post by:
private void listView1_SelectedIndexChanged(object sender, System.EventArgs e) { textBox1.Text = this.listView1.Items.SubItems.Text; } This will display sub item after cklicking on item I...
2
by: Max Adams | last post by:
ListView - changing the text of subitem n? All, How can I change the text of a specific subitem of a specific ListViewItem? I want to have some "Status" column which I want to continually update...
0
by: Popoxinhxan | last post by:
Hi guy , i would like to have a Find search function like in Ms Excel to search for specific keyword in the list view. Could anyone help me to do so. Currently i can only get the index of the item...
6
by: Jano | last post by:
Hello. I have one question I make Listview with 4 columns. And I want add text to to column 2,3,4. With listview1->Items->add ("Text") I can add text only to first column. In Visual basic.NEt I...
2
by: H.B. | last post by:
Hi, How can I get the SubItem clicked in a ListView in detail mode. Thanks, Hugo
1
by: James | last post by:
Hi All, I have an ownerdraw ListView control. I'm trying to use an ownerdrawn ListView control to draw and display images in the second column of a listview which is set to detail view. I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.