XXXXXX not available in this context.

  • Thread starter Thread starter doofy
  • Start date Start date
D

doofy

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?
 
[...]
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
 
Peter said:
[...]
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

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.
 
[...]
private void connectToDBToolStripMenuItem_CLick(blah blah blah)
{
frmConnect.Show();
}

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
 
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.


--
Roger Frost
"Logic Is Syntax Independent"






doofy said:
Peter said:
[...]
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

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.
 
Roger said:
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.

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 said:
[...]
private void connectToDBToolStripMenuItem_CLick(blah blah blah)
{
frmConnect.Show();
}

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

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.
 
Peter said:
[...]
private void connectToDBToolStripMenuItem_CLick(blah blah blah)
{
    frmConnect.Show();
}
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).

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.- Zitierten Text ausblenden -

- 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
 
doofy said:
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.

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.
 
Peter said:
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.

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 said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top