Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Stephens' Visual Basic Programming 24-Hour Trainer
This is the forum to discuss the Wrox book Stephens' Visual Basic Programming 24-Hour Trainer by Rod Stephens; ISBN: 978-0-470-94335-9
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Stephens' Visual Basic Programming 24-Hour Trainer section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 20th, 2011, 07:40 PM
Authorized User
Points: 195, Level: 3
Points: 195, Level: 3 Points: 195, Level: 3 Points: 195, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Location: Tennessee
Posts: 46
Thanks: 27
Thanked 0 Times in 0 Posts
Unhappy Ex 13-3 frustration

A few of my names are different than yours, but I can't find the problem. My selected choice will not highlight. The SessionIndex is correct based on my MessageBox and by checking while debugging. My code is the same as your book code (with a few name variations). Your code hightlights properly, but mine does not . Since the SessionIndex is set correctly when the form loads it seems the the problem should be in this code, but I cannot find it.

Code:
Public Class SessionForm

    ' Public variables to communicate with the main form.
    Public SessionIndex As Integer
    Public SessionTitle As String

    ' Initialize the selection
    Private Sub SessionForm_Load() Handles MyBase.Load

        MessageBox.Show("SessionIndex is " & SessionIndex)

        lvwSession.SelectedIndices.Add(SessionIndex)

        ' Ensure that the selection is visible.
        lvwSession.SelectedItems(0).EnsureVisible()

    End Sub

    Private Sub btnOk_Click(sender As System.Object, e As System.EventArgs) Handles btnOk.Click

        ' Save the user's selection.
        SessionIndex = lvwSession.SelectedIndices(0)
        SessionTitle = lvwSession.SelectedItems(0).Text

    End Sub
End Class
Reply With Quote
  #2 (permalink)  
Old July 21st, 2011, 10:32 AM
Rod Stephens's Avatar
Wrox Author
Points: 3,166, Level: 23
Points: 3,166, Level: 23 Points: 3,166, Level: 23 Points: 3,166, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

I don't see offhand what's wrong with this.

If you zip up the project and send it to me at RodStephens@vb-helper.com, I'll take a look at it.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
Reply With Quote
The Following User Says Thank You to Rod Stephens For This Useful Post:
zavodney (July 21st, 2011)
  #3 (permalink)  
Old July 22nd, 2011, 04:48 PM
Rod Stephens's Avatar
Wrox Author
Points: 3,166, Level: 23
Points: 3,166, Level: 23 Points: 3,166, Level: 23 Points: 3,166, Level: 23
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2006
Location: , , .
Posts: 647
Thanks: 2
Thanked 96 Times in 95 Posts
Default

Wow! That was tricky. It turns out that your code was working correctly but the focus was initially on the OK button. The ListView control doesn't highlight the selected row when it doesn't have the focus. (I think on some controls you can set a property telling it to display the selection even if they don't have the focus but I guess this version of the ListView doesn't do that.) It's stupid but I think you're stuck with this behavior unless you use a different control or make your own.

Anyway, you can see the selection if you press Tab a couple times to move focus to the ListView.

The best solution is probably to change the tab order so the ListView begins with the focus. Open the for for editing, click the form, open the View menu and select Tab Order. Click on the controls in the order you want them to be used in the tab order (click the ListView first) and press Esc to get out of the tab order view. Now when the form appears you should see the selection.

It's a good thing you sent me the project because it would have been really hard to figure this out without experimenting with it.

Let me know if you have other problems with it.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
Reply With Quote
The Following User Says Thank You to Rod Stephens For This Useful Post:
zavodney (July 23rd, 2011)
  #4 (permalink)  
Old July 23rd, 2011, 12:40 AM
Authorized User
Points: 195, Level: 3
Points: 195, Level: 3 Points: 195, Level: 3 Points: 195, Level: 3
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Location: Tennessee
Posts: 46
Thanks: 27
Thanked 0 Times in 0 Posts
Default

Thank you. I set the ListView to the first tab stop and it is working fine now. Little details can sure make a difference.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pure frustration vbboyd BOOK: Beginning ASP.NET 4 : in C# and VB 36 February 7th, 2015 11:52 AM
Pure frustration vbboyd BOOK: Beginning ASP.NET 4 : in C# and VB 1 May 16th, 2011 04:31 AM
move_uploaded_file frustration plugnz BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 February 18th, 2010 07:59 AM
Frustration with VB Editor jeremy1048 Access 3 October 26th, 2007 01:10 PM
using a expression causing frustration s.wright Access VBA 1 July 26th, 2006 03:37 PM



All times are GMT -4. The time now is 02:31 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.