Two ListView Controls on one form

J

Josef Brunner

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
 
T

Terry Olsen

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.
 
J

Josef Brunner

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
 
J

Josef Brunner

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
 
J

Jeffrey Tan[MSFT]

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.
 
J

Josef Brunner

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
 
J

Jeffrey Tan[MSFT]

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top