Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer
This is the forum to discuss the Wrox book Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer by Rod Stephens; ISBN: 9780470596906
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Stephens' C# Programming with Visual Studio 2010 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
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 27th, 2012, 07:25 PM
Registered User
Points: 19, Level: 1
Points: 19, Level: 1 Points: 19, Level: 1 Points: 19, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2012
Location: Juneau, AK
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Lesson 13 Exercise 3

I am having trouble with this exercise. There is no initial highlight for the PickSessionForm List View Box. The selection and highlight are not saved when I click the button to open the form again. Everything else works, the text is transferred between forms, just no initial or saved highlighted selection when the other form is opened.

The solution code works and my code was very similar. I spent an hour looking at my code on one monitor and the solution code on the other. The book mentions the load event handler is what controls what should be selected. My load event and OK button events are the same as the solution, as well as the button event handlers on the main form.

the load handler....
Code:
  // Initialize the selection
        private void PickSessionForm_Load(object sender, EventArgs e)
        {
            sessionsListView.SelectedIndices.Add(SessionIndex);
            
            // Ensure the selection is visible
            sessionsListView.SelectedItems[0].EnsureVisible();
        }
Could the problem be in the designer code or somewhere else?

Last edited by 1rf2aa3oa4tb; June 27th, 2012 at 07:45 PM..
  #2 (permalink)  
Old June 28th, 2012, 01:19 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

Quote:
Could the problem be in the designer code or somewhere else?
That's good intuition. If you're pretty sure the code is correct, then there is sometimes a property on the form set by the Form Designer that changes the way things work.

Here, however, I don't think there are any properties that would change this.

I suspect the problem is in the code that displays the form. If you look at the pick button event handlers on the main form, one of the things they do before displaying the session form is setting the session form's SessionIndex property with code like this:

Code:
frm.SessionIndex = SessionIndex1;
Then the session form's Load event handler uses the form's SessionIndex to initialize the selected item. If the main form's event handler doesn't set SessionIndex, then it would default to 0 and the session form would always initially select the first item (with index 0).

Let me know if that works.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
  #3 (permalink)  
Old July 2nd, 2012, 11:24 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

After looking at the project you emailed me, I found it. You did everything correctly but the list control on the selection form doesn't have the input focus when the form is displayed and Microsoft in its infinite wisdom decided that this type of control should not show you what items are selected unless it has the focus.

If you display the form and press tab until the list has focus, you'll see that the correct item is selected.

To fix this, open the form in the designer. Be sure the form is selected and not one of its controls. Then open the View menu and select Tab Order. Now click on the control in the order in which you want them to get focus. Click the list first so it gets the initial focus. Now when you run the program, the form should work as expected.

Sorry about the confusion.
__________________
Rod

Rod Stephens, Microsoft MVP

Essential Algorithms: A Practical Approach to Computer Algorithms

(Please post reviews at Amazon or wherever you shop!)
  #4 (permalink)  
Old July 2nd, 2012, 12:04 PM
Registered User
Points: 19, Level: 1
Points: 19, Level: 1 Points: 19, Level: 1 Points: 19, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2012
Location: Juneau, AK
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Rod Stephens View Post
To fix this, open the form in the designer. Be sure the form is selected and not one of its controls. Then open the View menu and select Tab Order. Now click on the control in the order in which you want them to get focus. Click the list first so it gets the initial focus. Now when you run the program, the form should work as expected.
Success. I can put this one week old mystery to bed. Thank you.
 


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
Lesson 4 Try it Exercise caa5042 BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer 13 February 2nd, 2013 03:32 PM
Lesson 4 Exercise 2 Rennuke BOOK: Stephens' Visual Basic Programming 24-Hour Trainer 3 January 17th, 2013 08:49 PM
Lesson 13 Try it error alawode BOOK: Knight's Microsoft Business Intelligence 24-Hour Trainer 4 January 27th, 2012 08:32 PM
Lesson 13: Task weird output gbargsley BOOK: Knight's 24-Hour Trainer: Microsoft SQL Server 2008 Integration Services 0 August 3rd, 2011 11:07 AM
Lesson 19 Exercise 4 mpthemaster BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer 3 June 11th, 2011 08:54 PM



All times are GMT -4. The time now is 09:13 PM.


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