p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Stephens' C# Programming with Visual Studio 2010 24-Hour Trainer (http://p2p.wrox.com/forumdisplay.php?f=574)
-   -   Lesson 13, Ex. 3 (http://p2p.wrox.com/showthread.php?t=90314)

John S June 10th, 2013 12:53 PM

Lesson 13, Ex. 3
Ok, I know what the project is supposed to do, and I can run the downloaded solution and it works.

I just have no idea what the code actually is doing, or what is making what happen.

Rod Stephens June 10th, 2013 02:46 PM

I'm away from my books and computer right now so I don't remember the details, but in general you might skim the lesson again. It should be covering the techniques uses by the Try It and exercises.

I'll try to post more details later today.

Rod Stephens June 10th, 2013 06:41 PM

I think you'll have to work through the exercise's requirements one at a time. Don't try to tackle the whole thing at once. Just focus on each task. You can either try to do them yourself or study the code to see where each requirement is met. Here are some notes about them.
Create private fields named SessionIndex1, SessionIndex2, and so forth to hold the indexes of the user’s choices.
This just means create some public variables inside the main form.
When the user clicks an ellipsis button, display the session selection dialog shown on the top in Figure 13-3.
When the user clicks the button, create a new session selection form variable as in:


SelectionForm frm = new SelectionForm();
After creating the dialog but before displaying it, set its Text property to indicate the session time as shown in the figure.
Set the dialog's Text property as in:


frm.Text = "Whatever";
Also before displaying the dialog, use code similar to the following to tell the dialog about the user’s previous selection for this session. (The SessionIndex and SessionTitle variables are public fields defined by the dialog and discussed shortly.)


frm.SessionIndex = SessionIndex1;
So this to set the form's SessionIndex property to the value in the main form's SessionIndex1 variable.

Now that you've prepared the dialog, call the dialog's ShowDialog method to display it.
If the user clicks OK, use code similar to the following to save the index of the user’s choice and to display the session’s title.
If the ShowDialog method returns OK to the main program's code, use the code to save the user's selection.
Set the ListView’s FullRowSelect property to True and set its MultiSelect property to False.

Use the Properties window to define the ListView’s column headers. Select the ListView, click its Columns property, click the ellipsis to the right, and use the editor to define the headers.

Use the Properties window’s editors to define the ListView’s items. Select the ListView, click its Items property, click the ellipsis to the right, and use the editor to define the items. Set the Text property to determine an item’s text. Click the SubItems property and then click the ellipsis to the right to define the sub-items (Room and Speaker).
Do the previous three tasks to prepare the form.
Use the following code to create public fields to communicate with the main form:
This code is in the session selection form. The main form can see it (it's public) so that's how the two forms communicate.
Create a Load event handler that uses the following code to initialize the dialog. This code selects the proper session in the ListView control and then makes the control scroll if necessary so that session is visible.
This code is in the session selection form. It gets the form ready to use.
In the OK button’s Click event handler, use the following code to save the selected item’s index and title for the main form to use:
This code is also in the session selection form. It sets the public variable values for the main form to read.

Hopefully this will help you get started or help you understand what the example code does.

All times are GMT -4. The time now is 02:20 PM.

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