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 6 2287
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
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
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
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
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
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
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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();...
|
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.
|
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...
|
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...
|
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...
|
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...
|
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?
|
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...
|
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...
|
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...
|
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...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
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...
|
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....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
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...
|
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...
| | |