473,748 Members | 2,887 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ListView only recognizes Items, how about SubItems?

Hi. I use a ListView to display data in tabular form.

Each ListView row corresponds to a data record.
The ListView Item of the record is the record key or code.
Each SubItem in that row represents a field from the record.

I implemented a context menu so the user can "Copy" the cell content to the
clipboard with this code:
Private Sub ListView1_Mouse Down(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles ListView1.Mouse Down
'Displays a context menu with the option to "Copy" to the clipboard.

'Activate context menu if user right-clicked.
If e.Button = MouseButtons.Ri ght Then
Dim ClickPoint As Point = New Point(e.X, e.Y)
Dim LVItem As ListViewItem = ListView1.GetIt emAt(ClickPoint .X,
ClickPoint.Y)

'Copy data only if item contains some data.
If Not LVItem Is Nothing Then
'Code to copy to ciipboard...
End If
End If
End Sub

The problem is that GetItemAt() returns Nothing if the click happened on a
SubItem, that is, any column but the leftmost.
How can I allow the users to copy the data from the other columns to the
clipboard?

Thanks in advance

Richard
Jul 21 '05 #1
6 2333
I've seen people having problems with this. In theory, you should get the
ListView Item even when you click on the subitems (as per documentation of
the GetItemAt method). You can try one of these:

1. Try putting your code in the mouseup event instead of the mouse down
event.

2. If you absolutely want it in the mousedown event, you could do something
like this:

Dim p As Point = ListView1.Point ToClient( _
New Point(Cursor.Po sition.X, Cursor.Position .Y))

Dim LVItem As ListViewItem = ListView1.GetIt emAt(p.X, p.Y)

hope that helps..
Imran.

"Richard" <Ri*****@discus sions.microsoft .com> wrote in message
news:E2******** *************** ***********@mic rosoft.com...
Hi. I use a ListView to display data in tabular form.

Each ListView row corresponds to a data record.
The ListView Item of the record is the record key or code.
Each SubItem in that row represents a field from the record.

I implemented a context menu so the user can "Copy" the cell content to the clipboard with this code:
Private Sub ListView1_Mouse Down(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles ListView1.Mouse Down
'Displays a context menu with the option to "Copy" to the clipboard.
'Activate context menu if user right-clicked.
If e.Button = MouseButtons.Ri ght Then
Dim ClickPoint As Point = New Point(e.X, e.Y)
Dim LVItem As ListViewItem = ListView1.GetIt emAt(ClickPoint .X,
ClickPoint.Y)

'Copy data only if item contains some data.
If Not LVItem Is Nothing Then
'Code to copy to ciipboard...
End If
End If
End Sub

The problem is that GetItemAt() returns Nothing if the click happened on a
SubItem, that is, any column but the leftmost.
How can I allow the users to copy the data from the other columns to the
clipboard?

Thanks in advance

Richard

Jul 21 '05 #2
Thank you Imran, but this is not a viable solution.
It seems that ListView1.GetIt emAt() method only returns something when
clicked on the Item (the 1st column of the ListView). When a subitem (any
other column) is clicked, It returns Nothing.

Thank you,

Richard

"Imran Koradia" wrote:
I've seen people having problems with this. In theory, you should get the
ListView Item even when you click on the subitems (as per documentation of
the GetItemAt method). You can try one of these:

1. Try putting your code in the mouseup event instead of the mouse down
event.

2. If you absolutely want it in the mousedown event, you could do something
like this:

Dim p As Point = ListView1.Point ToClient( _
New Point(Cursor.Po sition.X, Cursor.Position .Y))

Dim LVItem As ListViewItem = ListView1.GetIt emAt(p.X, p.Y)

hope that helps..
Imran.

"Richard" <Ri*****@discus sions.microsoft .com> wrote in message
news:E2******** *************** ***********@mic rosoft.com...
Hi. I use a ListView to display data in tabular form.

Each ListView row corresponds to a data record.
The ListView Item of the record is the record key or code.
Each SubItem in that row represents a field from the record.

I implemented a context menu so the user can "Copy" the cell content to

the
clipboard with this code:
Private Sub ListView1_Mouse Down(ByVal sender As Object, ByVal e As
System.Windows. Forms.MouseEven tArgs) Handles ListView1.Mouse Down
'Displays a context menu with the option to "Copy" to the

clipboard.

'Activate context menu if user right-clicked.
If e.Button = MouseButtons.Ri ght Then
Dim ClickPoint As Point = New Point(e.X, e.Y)
Dim LVItem As ListViewItem = ListView1.GetIt emAt(ClickPoint .X,
ClickPoint.Y)

'Copy data only if item contains some data.
If Not LVItem Is Nothing Then
'Code to copy to ciipboard...
End If
End If
End Sub

The problem is that GetItemAt() returns Nothing if the click happened on a
SubItem, that is, any column but the leftmost.
How can I allow the users to copy the data from the other columns to the
clipboard?

Thanks in advance

Richard


Jul 21 '05 #3
There is a property (don't have VS where I am) that will determine when the
GUI will respond to a mouse click to select an item. If you don't set this
the listview item will only be selected if you click the first column. I
would bet that the GetItemAt will respond in the same manner. Set this
property to true and I think you will get what you are looking for.

Lloyd Sheen

"Richard" <Ri*****@discus sions.microsoft .com> wrote in message
news:C0******** *************** ***********@mic rosoft.com...
Thank you Imran, but this is not a viable solution.
It seems that ListView1.GetIt emAt() method only returns something when
clicked on the Item (the 1st column of the ListView). When a subitem (any
other column) is clicked, It returns Nothing.

Thank you,

Richard

"Imran Koradia" wrote:
I've seen people having problems with this. In theory, you should get the
ListView Item even when you click on the subitems (as per documentation
of
the GetItemAt method). You can try one of these:

1. Try putting your code in the mouseup event instead of the mouse down
event.

2. If you absolutely want it in the mousedown event, you could do
something
like this:

Dim p As Point = ListView1.Point ToClient( _
New Point(Cursor.Po sition.X, Cursor.Position .Y))

Dim LVItem As ListViewItem = ListView1.GetIt emAt(p.X, p.Y)

hope that helps..
Imran.

"Richard" <Ri*****@discus sions.microsoft .com> wrote in message
news:E2******** *************** ***********@mic rosoft.com...
> Hi. I use a ListView to display data in tabular form.
>
> Each ListView row corresponds to a data record.
> The ListView Item of the record is the record key or code.
> Each SubItem in that row represents a field from the record.
>
> I implemented a context menu so the user can "Copy" the cell content to

the
> clipboard with this code:
>
>
> Private Sub ListView1_Mouse Down(ByVal sender As Object, ByVal e As
> System.Windows. Forms.MouseEven tArgs) Handles ListView1.Mouse Down
> 'Displays a context menu with the option to "Copy" to the

clipboard.
>
> 'Activate context menu if user right-clicked.
> If e.Button = MouseButtons.Ri ght Then
> Dim ClickPoint As Point = New Point(e.X, e.Y)
> Dim LVItem As ListViewItem =
> ListView1.GetIt emAt(ClickPoint .X,
> ClickPoint.Y)
>
> 'Copy data only if item contains some data.
> If Not LVItem Is Nothing Then
> 'Code to copy to ciipboard...
> End If
> End If
> End Sub
>
> The problem is that GetItemAt() returns Nothing if the click happened
> on a
> SubItem, that is, any column but the leftmost.
> How can I allow the users to copy the data from the other columns to
> the
> clipboard?
>
> Thanks in advance
>
> Richard


Jul 21 '05 #4
Property is FullRowSelect

Lloyd Sheen

"Lloyd Sheen" <sq************ *******@tostops pamhotmail.com> wrote in message
news:oI******** *******@news04. bloor.is.net.ca ble.rogers.com. ..
There is a property (don't have VS where I am) that will determine when
the GUI will respond to a mouse click to select an item. If you don't set
this the listview item will only be selected if you click the first
column. I would bet that the GetItemAt will respond in the same manner.
Set this property to true and I think you will get what you are looking
for.

Lloyd Sheen

"Richard" <Ri*****@discus sions.microsoft .com> wrote in message
news:C0******** *************** ***********@mic rosoft.com...
Thank you Imran, but this is not a viable solution.
It seems that ListView1.GetIt emAt() method only returns something when
clicked on the Item (the 1st column of the ListView). When a subitem (any
other column) is clicked, It returns Nothing.

Thank you,

Richard

"Imran Koradia" wrote:
I've seen people having problems with this. In theory, you should get
the
ListView Item even when you click on the subitems (as per documentation
of
the GetItemAt method). You can try one of these:

1. Try putting your code in the mouseup event instead of the mouse down
event.

2. If you absolutely want it in the mousedown event, you could do
something
like this:

Dim p As Point = ListView1.Point ToClient( _
New Point(Cursor.Po sition.X, Cursor.Position .Y))

Dim LVItem As ListViewItem = ListView1.GetIt emAt(p.X, p.Y)

hope that helps..
Imran.

"Richard" <Ri*****@discus sions.microsoft .com> wrote in message
news:E2******** *************** ***********@mic rosoft.com...
> Hi. I use a ListView to display data in tabular form.
>
> Each ListView row corresponds to a data record.
> The ListView Item of the record is the record key or code.
> Each SubItem in that row represents a field from the record.
>
> I implemented a context menu so the user can "Copy" the cell content
> to
the
> clipboard with this code:
>
>
> Private Sub ListView1_Mouse Down(ByVal sender As Object, ByVal e As
> System.Windows. Forms.MouseEven tArgs) Handles ListView1.Mouse Down
> 'Displays a context menu with the option to "Copy" to the
clipboard.
>
> 'Activate context menu if user right-clicked.
> If e.Button = MouseButtons.Ri ght Then
> Dim ClickPoint As Point = New Point(e.X, e.Y)
> Dim LVItem As ListViewItem =
> ListView1.GetIt emAt(ClickPoint .X,
> ClickPoint.Y)
>
> 'Copy data only if item contains some data.
> If Not LVItem Is Nothing Then
> 'Code to copy to ciipboard...
> End If
> End If
> End Sub
>
> The problem is that GetItemAt() returns Nothing if the click happened
> on a
> SubItem, that is, any column but the leftmost.
> How can I allow the users to copy the data from the other columns to
> the
> clipboard?
>
> Thanks in advance
>
> Richard


Jul 21 '05 #5
Richard,

I believe Lloyd's answer should solve your problem. I looked in my code and
I've been using the same code you posted without any problems. I guess I
overlooked the fact that FullRowSelect was True in my case - I just assumed
you would have that set to True since that's how we are accustomed to using
listviews. You should set this property to True (from the designer or at
runtime - whichever) which will ensure that the entire row is highlighted
and then you should be able to get the listview item by clicking anywhere on
that row.

Imran.

"Richard" <Ri*****@discus sions.microsoft .com> wrote in message
news:C0******** *************** ***********@mic rosoft.com...
Thank you Imran, but this is not a viable solution.
It seems that ListView1.GetIt emAt() method only returns something when
clicked on the Item (the 1st column of the ListView). When a subitem (any
other column) is clicked, It returns Nothing.

Thank you,

Richard

"Imran Koradia" wrote:
I've seen people having problems with this. In theory, you should get the
ListView Item even when you click on the subitems (as per documentation
of
the GetItemAt method). You can try one of these:

1. Try putting your code in the mouseup event instead of the mouse down
event.

2. If you absolutely want it in the mousedown event, you could do
something
like this:

Dim p As Point = ListView1.Point ToClient( _
New Point(Cursor.Po sition.X, Cursor.Position .Y))

Dim LVItem As ListViewItem = ListView1.GetIt emAt(p.X, p.Y)

hope that helps..
Imran.

"Richard" <Ri*****@discus sions.microsoft .com> wrote in message
news:E2******** *************** ***********@mic rosoft.com...
> Hi. I use a ListView to display data in tabular form.
>
> Each ListView row corresponds to a data record.
> The ListView Item of the record is the record key or code.
> Each SubItem in that row represents a field from the record.
>
> I implemented a context menu so the user can "Copy" the cell content to

the
> clipboard with this code:
>
>
> Private Sub ListView1_Mouse Down(ByVal sender As Object, ByVal e As
> System.Windows. Forms.MouseEven tArgs) Handles ListView1.Mouse Down
> 'Displays a context menu with the option to "Copy" to the

clipboard.
>
> 'Activate context menu if user right-clicked.
> If e.Button = MouseButtons.Ri ght Then
> Dim ClickPoint As Point = New Point(e.X, e.Y)
> Dim LVItem As ListViewItem =
> ListView1.GetIt emAt(ClickPoint .X,
> ClickPoint.Y)
>
> 'Copy data only if item contains some data.
> If Not LVItem Is Nothing Then
> 'Code to copy to ciipboard...
> End If
> End If
> End Sub
>
> The problem is that GetItemAt() returns Nothing if the click happened
> on a
> SubItem, that is, any column but the leftmost.
> How can I allow the users to copy the data from the other columns to
> the
> clipboard?
>
> Thanks in advance
>
> Richard


Jul 21 '05 #6
Thank you Lloyd, you are right, with FullRowSelect = True the Item becomes
the whole line and it recognizes the click. In order to find the subitem that
was clicked, I suppose I will have to calculate the width of each column in
pixels. Is that correct?

Thank you

Richard

"Lloyd Sheen" wrote:
Property is FullRowSelect

Lloyd Sheen

"Lloyd Sheen" <sq************ *******@tostops pamhotmail.com> wrote in message
news:oI******** *******@news04. bloor.is.net.ca ble.rogers.com. ..
There is a property (don't have VS where I am) that will determine when
the GUI will respond to a mouse click to select an item. If you don't set
this the listview item will only be selected if you click the first
column. I would bet that the GetItemAt will respond in the same manner.
Set this property to true and I think you will get what you are looking
for.

Lloyd Sheen

"Richard" <Ri*****@discus sions.microsoft .com> wrote in message
news:C0******** *************** ***********@mic rosoft.com...
Thank you Imran, but this is not a viable solution.
It seems that ListView1.GetIt emAt() method only returns something when
clicked on the Item (the 1st column of the ListView). When a subitem (any
other column) is clicked, It returns Nothing.

Thank you,

Richard

"Imran Koradia" wrote:

I've seen people having problems with this. In theory, you should get
the
ListView Item even when you click on the subitems (as per documentation
of
the GetItemAt method). You can try one of these:

1. Try putting your code in the mouseup event instead of the mouse down
event.

2. If you absolutely want it in the mousedown event, you could do
something
like this:

Dim p As Point = ListView1.Point ToClient( _
New Point(Cursor.Po sition.X, Cursor.Position .Y))

Dim LVItem As ListViewItem = ListView1.GetIt emAt(p.X, p.Y)

hope that helps..
Imran.

"Richard" <Ri*****@discus sions.microsoft .com> wrote in message
news:E2******** *************** ***********@mic rosoft.com...
> Hi. I use a ListView to display data in tabular form.
>
> Each ListView row corresponds to a data record.
> The ListView Item of the record is the record key or code.
> Each SubItem in that row represents a field from the record.
>
> I implemented a context menu so the user can "Copy" the cell content
> to
the
> clipboard with this code:
>
>
> Private Sub ListView1_Mouse Down(ByVal sender As Object, ByVal e As
> System.Windows. Forms.MouseEven tArgs) Handles ListView1.Mouse Down
> 'Displays a context menu with the option to "Copy" to the
clipboard.
>
> 'Activate context menu if user right-clicked.
> If e.Button = MouseButtons.Ri ght Then
> Dim ClickPoint As Point = New Point(e.X, e.Y)
> Dim LVItem As ListViewItem =
> ListView1.GetIt emAt(ClickPoint .X,
> ClickPoint.Y)
>
> 'Copy data only if item contains some data.
> If Not LVItem Is Nothing Then
> 'Code to copy to ciipboard...
> End If
> End If
> End Sub
>
> The problem is that GetItemAt() returns Nothing if the click happened
> on a
> SubItem, that is, any column but the leftmost.
> How can I allow the users to copy the data from the other columns to
> the
> clipboard?
>
> Thanks in advance
>
> Richard



Jul 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
4658
by: VM | last post by:
How can I fill up a listview with text file contents? My listview has two columns and the first column fills up with a while loop: while (myString != null) { myString = sr.Readline(); listView1.Items.Add (myString); } Is there a way I can fill up the second column this easily? Thw way I'm currently doing it is using the subitems property to add it. Unfortunately,
4
9711
by: Paddy | last post by:
How do I select a subitem from a listview after clicking on the first column? Couldn't find it in MSDN. Thank you. Paddy.
21
5218
by: StriderBob | last post by:
Situation : FormX is mdi child form containing 2 ListViews ListView1 contains a list of table names and 4 sub items with data about each table. ListView2 contains a list of the columns on each table and 11 sub items with data about each column. When a Row in ListView1 is selected the Data in ListVies2 is loaded to show the correct data. Initially the first row in ListView1 is selected in FormX load
20
6670
by: Ash Phillips | last post by:
Hi Everyone, I have this program I wrote in VB6 for family use. It's a DVD Database just for me to keep track of them cause I have so many lol. In VB6, I could add items to the ListView in 'frmMain' from 'frmAdd' with the following code: Private Function AddEntry(Title As String, Rating As String, Genre As String, OnLoan As Boolean, ToWho As String)
12
3127
by: Dennis | last post by:
I have a form which has a ListView control named ListView1 added at design time. When I add items using the following code, they don't appear in the list view. However, if I create a ListView control in code and add it to the form, it works. Why don't the items show up in the ListView that I added at desgn time. ' Create three items and three sets of subitems for each item. Dim item1 As New ListViewItem("item1", 0) ' Place a check...
6
439
by: Richard | last post by:
Hi. I use a ListView to display data in tabular form. Each ListView row corresponds to a data record. The ListView Item of the record is the record key or code. Each SubItem in that row represents a field from the record. I implemented a context menu so the user can "Copy" the cell content to the clipboard with this code:
1
2040
by: Joe | last post by:
I set up two columns in listview. I use Add to add items, but how do I access the second column? and add text?
3
5409
by: Martin Panggabean | last post by:
Hello All, I've kind a logic problem ... I want to fill the listView control in VB.NET with data in my mySql table using Datareader object component. But It seems that the way of how listView being used is quite different from usual column-row component like Grid component. If you kind a familiar using listView, u must have known what i'm talking about. Here is some example i took from MSDN :...
1
2058
by: samoore33 | last post by:
I found this code on MSDN, and it works great. It creates a ListView dynamically and add items to it and all. It is great. I have changed a few of the column names to suit me. Dim listView1 As New ListView listView1.Bounds = New Rectangle(New Point(10, 10), New Size(300, 200)) ' Set the view to show details.
0
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8830
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9544
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9324
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9247
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8243
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
3313
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.