Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / March 2006

Tip: Looking for answers? Try searching our database.

ListView.SelectedIndexChanged behavior

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mark Smith - 31 Mar 2006 01:25 GMT
I have a single-selection ListView where I always want to keep an item
selected by default.  If the user clicks in the empty area below the
items, I want to select the first item.  

It appears that when the user selects a new item, two
SelectedIndexChanged events are fired: one with no SelectedItems, and
then one with the new SelectedItem.  Because of that, I can't tell if
an event with no selection is because the user clicked outside the
list items (and I should select the first one) or because they
selected another item (and I shouldn't).  

Does anyone know a workaround for this?
Jared - 31 Mar 2006 01:56 GMT
From MouseClick event

MyListViewHitTestInfo = ListView1.HitTest(New Point(e.X, e.Y)

if MyListViewHitTestInfo.item is nothing then
me.ListView1.items(0).selected=true
me.ListView1.Select
End If

Should work well with you SIC event as well.

>I have a single-selection ListView where I always want to keep an item
> selected by default.  If the user clicks in the empty area below the
[quoted text clipped - 8 lines]
>
> Does anyone know a workaround for this?
Mark Smith - 31 Mar 2006 16:39 GMT
>From MouseClick event
>
[quoted text clipped - 4 lines]
>me.ListView1.Select
>End If

Hi Jared, thanks for the suggestion.  Unfortunately, the ListView
doesn't fire a MouseClick event in the area below the items, so it
won't work...
Jared - 31 Mar 2006 21:21 GMT
MouseUp will do ...

Private Sub ListView1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles ListView1.MouseUp

Dim HTI0 As ListViewHitTestInfo

HTI0 = Me.ListView1.HitTest(New Point(e.X, e.Y))

If HTI0.Item Is Nothing Then

Trace.WriteLine(True)

Else

Trace.WriteLine(False)

End If

End Sub

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.