By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,994 Members | 1,407 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,994 IT Pros & Developers. It's quick & easy.

Two ListView Controls on one form

P: n/a
Hi,

I have a problem using two ListView controls on one and the same form:

Problem: The second ListView is never focused. No matter where I "click" non
of the items within the ListView is focused.

This is only the matter for the secondly added ListView!!! The first one
works perfectly!!

Example:

' Works perfectly -- Displays a message box with the text of the item where
I clicked
Private Sub ListView1_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDown
MsgBox("focussed item :" + ListView1.FocusedItem.Text.ToString)

End Sub

' Crashes saying that ListView2 has no FocusedItem! But I'm sure I
definitely clicked on the item like I do on the first ListView

Private Sub ListView2_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles ListView2.MouseDown

MsgBox("focussed item :" + ListView2.FocusedItem.Text.ToString)

End Sub

Any ideas would be very appreciated,

Joe
Dec 1 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Have you tried deleting ListView2 and then re-adding it to the form? It's
possible that one of the properties got set wrong, though I have no idea
what it could be. If the Enabled property were set to False, it wouldn't
even catch the mouse-click.

"Josef Brunner" <jo**@newsgroups.nospam> wrote in message
news:et**************@TK2MSFTNGP09.phx.gbl...
Hi,

I have a problem using two ListView controls on one and the same form:

Problem: The second ListView is never focused. No matter where I "click"
non of the items within the ListView is focused.

This is only the matter for the secondly added ListView!!! The first one
works perfectly!!

Example:

' Works perfectly -- Displays a message box with the text of the item
where I clicked
Private Sub ListView1_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDown
MsgBox("focussed item :" + ListView1.FocusedItem.Text.ToString)

End Sub

' Crashes saying that ListView2 has no FocusedItem! But I'm sure I
definitely clicked on the item like I do on the first ListView

Private Sub ListView2_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles ListView2.MouseDown

MsgBox("focussed item :" + ListView2.FocusedItem.Text.ToString)

End Sub

Any ideas would be very appreciated,

Joe

Dec 1 '05 #2

P: n/a
Hi again,

thank for your fast reply :)

I already tried creating a new project, adding two ListView controls (no
changes to any properties, Enabled is default), adding a column and a single
item to each ListView.

Then I define the event "Mouse_Down" where I set a break point to check
whether the controls/items are focused.

It works perfectly for the first ListView but not for the second one?!
Strange isn't it?!

Thanks again,
Joe

"Terry Olsen" <to******@hotmail.com> schrieb im Newsbeitrag
news:%2*****************@TK2MSFTNGP15.phx.gbl...
Have you tried deleting ListView2 and then re-adding it to the form? It's
possible that one of the properties got set wrong, though I have no idea
what it could be. If the Enabled property were set to False, it wouldn't
even catch the mouse-click.

"Josef Brunner" <jo**@newsgroups.nospam> wrote in message
news:et**************@TK2MSFTNGP09.phx.gbl...
Hi,

I have a problem using two ListView controls on one and the same form:

Problem: The second ListView is never focused. No matter where I "click"
non of the items within the ListView is focused.

This is only the matter for the secondly added ListView!!! The first one
works perfectly!!

Example:

' Works perfectly -- Displays a message box with the text of the item
where I clicked
Private Sub ListView1_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseDown
MsgBox("focussed item :" + ListView1.FocusedItem.Text.ToString)

End Sub

' Crashes saying that ListView2 has no FocusedItem! But I'm sure I
definitely clicked on the item like I do on the first ListView

Private Sub ListView2_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles ListView2.MouseDown

MsgBox("focussed item :" + ListView2.FocusedItem.Text.ToString)

End Sub

Any ideas would be very appreciated,

Joe


Dec 1 '05 #3

P: n/a
Hi Jeffrey,

thanx for your help. What I did:

- I compiled and started your sample program
- I click on the item on the first (upper) ListView control -- displays the
message box correctly
- After that I click on the item on the second (lower) ListView control --
displays the error message that there is no focuseditem for this ListView

Maybe my OS or dot.net framework somehow got messed up??

I really have no clue what to do on this. Sure I can come around on that
problem by inserting this on the mouse_down event:
Dim myItem As ListViewItem = ListView2.GetItemAt(e.X, e.Y)
myItem.Focused = True

But this doesn't work for other events I use, like Double_Click since there
the "e" object has no X and Y coordinates to get the focuseditem

Really appreciate your help,
Kurt
""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> schrieb im Newsbeitrag
news:xf**************@TK2MSFTNGXA02.phx.gbl...
Hi Josef,

Thanks for your post.

First, because you are adding column, so I assumed that you use Details
mode for ListViews.

Currently, I have created a sample for you. However, it works well on my
side.

I have attached my sample project in this reply. You can get it with
Outlook Express(can not get with IE)

Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Dec 2 '05 #4

P: n/a
Hi Kurt,

Thanks for your feedback.

Currently, I do not have much idea about the root cause, it seems it is
caused by the OS and .Net Framework.

Can we try re-install the OS or the .Net Framework? I think this may
resolve this problem.

Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Dec 5 '05 #5

P: n/a
Hi Jeffrey,

thanks for staying with me in this problem :)

I just installed the new Visual Studio 2005 (with the latest 2.0 framework)
and it still won't work. Maybe you're right, maybe it is the OS, but
reinstalling it will be difficult. I will test it on another machine...

thx-a-lot
Kurt
""Jeffrey Tan[MSFT]"" <v-*****@online.microsoft.com> schrieb im Newsbeitrag
news:Br****************@TK2MSFTNGXA02.phx.gbl...
Hi Kurt,

Thanks for your feedback.

Currently, I do not have much idea about the root cause, it seems it is
caused by the OS and .Net Framework.

Can we try re-install the OS or the .Net Framework? I think this may
resolve this problem.

Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Dec 6 '05 #6

P: n/a
Hi Josef,

Yes, I also recommanded first testing on another machine before
re-installing OS. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Dec 7 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.