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)
-   -   Chapter 10 Tryit (http://p2p.wrox.com/showthread.php?t=83734)

Mark P. May 20th, 2011 01:01 PM

Chapter 10 Tryit
 
I'm sure this is something simple, but I can't seem to find the solution. On the Chapter 10 Tryit, when I enter the action for the if statement to add the name to the the list box, I'm getting an error that says, "NewComedianForm.nametext is inacessible due to its protection level.

Rod Stephens May 21st, 2011 10:11 AM

By default in C# a control's variable is declared private so other form's can't access it directly. You can change that by setting it's Modifiers property to public.

Purists argue that you should not do this, that instead you should create a public property to get and set the control's value. In this case you would create a Name property that would get and set NameTextBox.Text.

I don't think it's that big a deal because it's pretty clear how you use a TextBox so code outside the form is less likely to mess it up. So I'd probably just set the Modifier to public and you should be good to go.

Doug Snyder June 20th, 2011 05:36 PM

Same problem with comedianListBox
 
Even after I changed the modifier to "Public" for the Form1 list box "comedianListBox" . I get an error that it is not recognized. Any more suggestions?

Rod Stephens June 20th, 2011 08:20 PM

"Not recognized" usually means Visual Studio doesn't know that the control exists. Double check your spelling to make sure you have the right name.

Where is the code that's trying to use the control? If it's in Form1, it should be able to see all of the controls in Form1. If it's in the other form, you would need to change the Modifiers property.

If you can't figure it out, you can zip up the project and email it to RodStephens@CSharpHelper.com and I'll take a look.


All times are GMT -4. The time now is 01:55 PM.

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