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 / Languages / C# / February 2008

Tip: Looking for answers? Try searching our database.

XXXXXX not available in this context.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
doofy - 25 Feb 2008 03:53 GMT
I'm trying to create a custom control which would be a treeview which
populates itself with table and field details from a database.

I need to be able to call up a form to enter the server/db information.

I created a form within the custom control, and I sort of thought it
might not work, and it isn't.

It's telling me "frmConnect" is not available in this context.

Any ideas what is causing this?
Peter Duniho - 25 Feb 2008 04:00 GMT
> [...]
> It's telling me "frmConnect" is not available in this context.
>
> Any ideas what is causing this?

Since you didn't post any code at all, it's pretty much impossible to say  
for sure.  But presumably you are using the identifier "frmConnect" in a  
context in which it's not available.

Whatever that identifier is, you need to make sure you're using it in a  
way that makes sense.

If you'd like to post some code, then some advice as to what "makes sense"  
can be offered.  Otherwise, your question is far too vague to be answered.

Pete
doofy - 25 Feb 2008 05:04 GMT
>> [...]
>> It's telling me "frmConnect" is not available in this context.
[quoted text clipped - 13 lines]
>
> Pete

Sorry about that.  I thought maybe it was a generalized question.  The
code's on another machine.

private void connectToDBToolStripMenuItem_CLick(blah blah blah)
{
    frmConnect.Show();
}

frmConnect is a form that is within the custom control environment.

Is more code than that needed?  If so, I'll have to wait until later.

I have showing a treeview, a context menu on right click of the tree
view, and I'm calling this form from the menu to input the connection
string parameters.
Peter Duniho - 25 Feb 2008 05:37 GMT
> [...]
> private void connectToDBToolStripMenuItem_CLick(blah blah blah)
[quoted text clipped - 3 lines]
>
> frmConnect is a form that is within the custom control environment.

What do you mean by "custom control environment"?  What environment?

And what do you mean by "is a form"?  Is that a variable to which has been  
assigned an instance of a class that inherits Form?  Or is it the name of  
a class that inherits Form?  Is this a compiler error?  Or run-time?  What  
is the _exact_ error text you're getting and in what context?

It kind of looks like you're trying to do in C# something that would work  
in VB (but which you shouldn't do anyway, IMHO).  But it's hard to say  
without more specific information about what's actually going on (see the  
previous paragraph for the kinds of specific information you've left out).

Pete
doofy - 25 Feb 2008 06:47 GMT
>> [...]
>> private void connectToDBToolStripMenuItem_CLick(blah blah blah)
[quoted text clipped - 19 lines]
>
> Pete

You're probably right, as I posted in the other email.

I don't know what the proper vernacular is.  I'm in a custom control
project.  I created a form within that project, thus the "custom control
environment".

I'll have to transfer the code from the other machine to here when I get
a chance.

I believe the info you've both given me in these last two posts might
point to the problem.

This is the first time I've tried to create a custom control, in any
language, so I'm sort of slogging through.  Thanks for your help and
patience.
KWienhold - 25 Feb 2008 06:56 GMT
> >> [...]
> >> private void connectToDBToolStripMenuItem_CLick(blah blah blah)
[quoted text clipped - 37 lines]
>
> - Zitierten Text anzeigen -

I believe in VB there was a "default instance" of every form, so you
could call <FormType>.Show() and it would display that default
instance.
In C# this doesn't work, you'll have to create an instance of the form
before showing it, like so (assuming frmConnect is the name of the
class):
frmConnect FormConnect = new frmConnect();
FormConnect.Show();

hth,
Kevin Wienhold
Roger Frost - 25 Feb 2008 05:44 GMT
Is a frmConnect instance declared (or a public instance referred to) in the
class that contains your connectToDBToolStripMenuItem_CLick method?

For example:

FormConnect frmConnect = new FormConnect();

Is IntelliSense (if your using an environment that utilizes it) working with
frmConnect (ie. does it auto complete such things as frmConnect.Show() while
typing)?

If IntelliSense "knows who it is" then the complier should as well.

Signature

Roger Frost
"Logic Is Syntax Independent"

>>> [...]
>>> It's telling me "frmConnect" is not available in this context.
[quoted text clipped - 29 lines]
> and I'm calling this form from the menu to input the connection string
> parameters.
doofy - 25 Feb 2008 06:43 GMT
> Is a frmConnect instance declared (or a public instance referred to) in
> the class that contains your connectToDBToolStripMenuItem_CLick method?
[quoted text clipped - 8 lines]
>
> If IntelliSense "knows who it is" then the complier should as well.

Know, Intellisense isn't getting it.  I'll try what you say above.

I'm just getting used to the .Net stuff and object instantiation
minutia.  I'm too used to VB6 ways.
Peter Webb - 25 Feb 2008 07:00 GMT
>> Is a frmConnect instance declared (or a public instance referred to) in
>> the class that contains your connectToDBToolStripMenuItem_CLick method?
[quoted text clipped - 13 lines]
> I'm just getting used to the .Net stuff and object instantiation minutia.
> I'm too used to VB6 ways.

I'm a newbie, and I get that problem all the time.

I bet you have created your method inside another class by mistake. Try
moving it somewhere else.
doofy - 25 Feb 2008 14:14 GMT
>>> Is a frmConnect instance declared (or a public instance referred to)
>>> in the class that contains your connectToDBToolStripMenuItem_CLick
[quoted text clipped - 19 lines]
> I bet you have created your method inside another class by mistake. Try
> moving it somewhere else.

it is.  It's in another namespace too.  I just told it to add a form to
the project, and that's what it did.
doofy - 27 Feb 2008 13:42 GMT
> it is.  It's in another namespace too.  I just told it to add a form to
> the project, and that's what it did.

I made it work by preceding the object name with the other namespace
name, and by instantiating it with "new".

Thanks for everyone's help in jogging my brain in the right direction.

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.