473,491 Members | 2,248 Online
Bytes | Software Development & Data Engineering Community
Create 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_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDown
'Displays a context menu with the option to "Copy" to the clipboard.

'Activate context menu if user right-clicked.
If e.Button = MouseButtons.Right Then
Dim ClickPoint As Point = New Point(e.X, e.Y)
Dim LVItem As ListViewItem = ListView1.GetItemAt(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 2298
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.PointToClient( _
New Point(Cursor.Position.X, Cursor.Position.Y))

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

hope that helps..
Imran.

"Richard" <Ri*****@discussions.microsoft.com> wrote in message
news:E2**********************************@microsof t.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_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDown
'Displays a context menu with the option to "Copy" to the clipboard.
'Activate context menu if user right-clicked.
If e.Button = MouseButtons.Right Then
Dim ClickPoint As Point = New Point(e.X, e.Y)
Dim LVItem As ListViewItem = ListView1.GetItemAt(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.GetItemAt() 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.PointToClient( _
New Point(Cursor.Position.X, Cursor.Position.Y))

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

hope that helps..
Imran.

"Richard" <Ri*****@discussions.microsoft.com> wrote in message
news:E2**********************************@microsof t.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_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDown
'Displays a context menu with the option to "Copy" to the

clipboard.

'Activate context menu if user right-clicked.
If e.Button = MouseButtons.Right Then
Dim ClickPoint As Point = New Point(e.X, e.Y)
Dim LVItem As ListViewItem = ListView1.GetItemAt(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*****@discussions.microsoft.com> wrote in message
news:C0**********************************@microsof t.com...
Thank you Imran, but this is not a viable solution.
It seems that ListView1.GetItemAt() 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.PointToClient( _
New Point(Cursor.Position.X, Cursor.Position.Y))

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

hope that helps..
Imran.

"Richard" <Ri*****@discussions.microsoft.com> wrote in message
news:E2**********************************@microsof t.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_MouseDown(ByVal sender As Object, ByVal e As
> System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDown
> 'Displays a context menu with the option to "Copy" to the

clipboard.
>
> 'Activate context menu if user right-clicked.
> If e.Button = MouseButtons.Right Then
> Dim ClickPoint As Point = New Point(e.X, e.Y)
> Dim LVItem As ListViewItem =
> ListView1.GetItemAt(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*******************@tostopspamhotmail.com> wrote in message
news:oI***************@news04.bloor.is.net.cable.r ogers.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*****@discussions.microsoft.com> wrote in message
news:C0**********************************@microsof t.com...
Thank you Imran, but this is not a viable solution.
It seems that ListView1.GetItemAt() 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.PointToClient( _
New Point(Cursor.Position.X, Cursor.Position.Y))

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

hope that helps..
Imran.

"Richard" <Ri*****@discussions.microsoft.com> wrote in message
news:E2**********************************@microsof t.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_MouseDown(ByVal sender As Object, ByVal e As
> System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDown
> 'Displays a context menu with the option to "Copy" to the
clipboard.
>
> 'Activate context menu if user right-clicked.
> If e.Button = MouseButtons.Right Then
> Dim ClickPoint As Point = New Point(e.X, e.Y)
> Dim LVItem As ListViewItem =
> ListView1.GetItemAt(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*****@discussions.microsoft.com> wrote in message
news:C0**********************************@microsof t.com...
Thank you Imran, but this is not a viable solution.
It seems that ListView1.GetItemAt() 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.PointToClient( _
New Point(Cursor.Position.X, Cursor.Position.Y))

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

hope that helps..
Imran.

"Richard" <Ri*****@discussions.microsoft.com> wrote in message
news:E2**********************************@microsof t.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_MouseDown(ByVal sender As Object, ByVal e As
> System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDown
> 'Displays a context menu with the option to "Copy" to the

clipboard.
>
> 'Activate context menu if user right-clicked.
> If e.Button = MouseButtons.Right Then
> Dim ClickPoint As Point = New Point(e.X, e.Y)
> Dim LVItem As ListViewItem =
> ListView1.GetItemAt(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*******************@tostopspamhotmail.com> wrote in message
news:oI***************@news04.bloor.is.net.cable.r ogers.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*****@discussions.microsoft.com> wrote in message
news:C0**********************************@microsof t.com...
Thank you Imran, but this is not a viable solution.
It seems that ListView1.GetItemAt() 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.PointToClient( _
New Point(Cursor.Position.X, Cursor.Position.Y))

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

hope that helps..
Imran.

"Richard" <Ri*****@discussions.microsoft.com> wrote in message
news:E2**********************************@microsof t.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_MouseDown(ByVal sender As Object, ByVal e As
> System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDown
> 'Displays a context menu with the option to "Copy" to the
clipboard.
>
> 'Activate context menu if user right-clicked.
> If e.Button = MouseButtons.Right Then
> Dim ClickPoint As Point = New Point(e.X, e.Y)
> Dim LVItem As ListViewItem =
> ListView1.GetItemAt(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
4613
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();...
4
9695
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
5167
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...
20
6607
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...
12
3083
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...
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...
1
2022
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
5397
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...
1
2047
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...
0
6978
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...
0
7154
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,...
1
6858
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...
0
7360
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...
1
4881
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4578
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3086
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3076
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1392
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 ...

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.