Hello, I have a simple question,
I have a vb.net form with several buttons.
If I store the name of a button in a variable..
Dim TheName as string
TheName = Me.btnMyLittleButton.Name.ToString
How can I disable this button using the variable value?
I can do this:
Me.btnMyLittleButton.Enabled = False
However, how can I get the name of the button (stored in TheName
variable ) and use it to disable it?
Is there a way to accomplish this without going through all the
controls in the form?
Don't want something like this:
Dim ctr As Control
For Each ctr In CurrentControl.Controls
If ctr.Name = TheName Then
ctr.Enabled = False
End If
Next
or writing the control names into a hashtable
What I want is something simple as the original example
Me.btnMyLittleButton.Enabled = False ---TheName.enabled = False
Does anyone has something better?
Thanks! 7 5506
On Apr 16, 3:48 pm, "John Smith" <I...@NETZERO.NETwrote:
Hello, I have a simple question,
I have a vb.net form with several buttons.
If I store the name of a button in a variable..
Dim TheName as string
TheName = Me.btnMyLittleButton.Name.ToString
How can I disable this button using the variable value?
I can do this:
Me.btnMyLittleButton.Enabled = False
However, how can I get the name of the button (stored in TheName
variable ) and use it to disable it?
Is there a way to accomplish this without going through all the
controls in the form?
Don't want something like this:
Dim ctr As Control
For Each ctr In CurrentControl.Controls
If ctr.Name = TheName Then
ctr.Enabled = False
End If
Next
or writing the control names into a hashtable
What I want is something simple as the original example
Me.btnMyLittleButton.Enabled = False ---TheName.enabled = False
Does anyone has something better?
Thanks!
Me.Controls[TheName].Enabled = False
You can access a control in the control collection by it's name in
2005.
--
Tom Shelton
On Apr 16, 9:35 pm, Tom Shelton <tom_shel...@comcast.netwrote:
On Apr 16, 3:48 pm, "John Smith" <I...@NETZERO.NETwrote:
Hello, I have a simple question,
I have a vb.net form with several buttons.
If I store the name of a button in a variable..
Dim TheName as string
TheName = Me.btnMyLittleButton.Name.ToString
How can I disable this button using the variable value?
I can do this:
Me.btnMyLittleButton.Enabled = False
However, how can I get the name of the button (stored in TheName
variable ) and use it to disable it?
Is there a way to accomplish this without going through all the
controls in the form?
Don't want something like this:
Dim ctr As Control
For Each ctr In CurrentControl.Controls
If ctr.Name = TheName Then
ctr.Enabled = False
End If
Next
or writing the control names into a hashtable
What I want is something simple as the original example
Me.btnMyLittleButton.Enabled = False ---TheName.enabled = False
Does anyone has something better?
Thanks!
Me.Controls[TheName].Enabled = False
You can access a control in the control collection by it's name in
2005.
--
Tom Shelton- Hide quoted text -
- Show quoted text -
Hi Tom, thanks for replying, but I am not using vb.net 2005. I have
VB.NET 2003.
If I use that code, I get the 'Enabled' is not a member of 'string'
error.
On Apr 16, 5:48 pm, "John Smith" <I...@NETZERO.NETwrote:
Hello, I have a simple question,
I have a vb.net form with several buttons.
If I store the name of a button in a variable..
Dim TheName as string
TheName = Me.btnMyLittleButton.Name.ToString
How can I disable this button using the variable value?
I can do this:
Me.btnMyLittleButton.Enabled = False
However, how can I get the name of the button (stored in TheName
variable ) and use it to disable it?
Is there a way to accomplish this without going through all the
controls in the form?
Don't want something like this:
Dim ctr As Control
For Each ctr In CurrentControl.Controls
If ctr.Name = TheName Then
ctr.Enabled = False
End If
Next
or writing the control names into a hashtable
What I want is something simple as the original example
Me.btnMyLittleButton.Enabled = False ---TheName.enabled = False
Does anyone has something better?
Thanks!
Do you have to store the button name into a variable? It would be a
lot easier to just store the button into the variable:
Dim theButton as Button = Me.btnMyLittleButton
theButton.Enabled = False
Thanks,
Seth Rowe
Hi Rowe, thanks for replying.
Well.. I cannot store the button into the variable. I'm supposed to
only know the button name.
I've tried to set the variable as a string, then as an object, but so
far I can't get it right.
I really hope this could be as easy as what Tom suggested:
Me.Controls[TheName].Enabled = False
The problem is that whenever I use the me. part, I get an error saying
that the variable is not a member of my form.
Is there a way to cast the variable as the button name using something
like DirectCast?
Thanks for all your help!
Well.. I cannot store the button into the variable. I'm supposed to
only know the button name.
Is this a school assignment?
I see no other time when you're only "supposed to know" a button name.
Thanks,
Seth Rowe
On Apr 17, 12:44 pm, John Smith <I...@NETZERO.NETwrote:
Hi Rowe, thanks for replying.
Well.. I cannot store the button into the variable. I'm supposed to
only know the button name.
I've tried to set the variable as a string, then as an object, but so
far I can't get it right.
I really hope this could be as easy as what Tom suggested:
Me.Controls[TheName].Enabled = False
The problem is that whenever I use the me. part, I get an error saying
that the variable is not a member of my form.
Is there a way to cast the variable as the button name using something
like DirectCast?
Thanks for all your help!
On Apr 17, 12:52 pm, rowe_newsgroups <rowe_em...@yahoo.comwrote:
Well.. I cannot store the button into the variable. I'm supposed to
only know the button name.
Is this a school assignment?
I see no other time when you're only "supposed to know" a button name.
Thanks,
Seth Rowe
On Apr 17, 12:44 pm, John Smith <I...@NETZERO.NETwrote:
Hi Rowe, thanks for replying.
Well.. I cannot store the button into the variable. I'm supposed to
only know the button name.
I've tried to set the variable as a string, then as an object, but so
far I can't get it right.
I really hope this could be as easy as what Tom suggested:
Me.Controls[TheName].Enabled = False
The problem is that whenever I use the me. part, I get an error saying
that the variable is not a member of my form.
Is there a way to cast the variable as the button name using something
like DirectCast?
Thanks for all your help!- Hide quoted text -
- Show quoted text -
:-)
Yes, it is and it's driving me crazy!
On Apr 17, 2:10 pm, John Smith <I...@NETZERO.NETwrote:
On Apr 17, 12:52 pm, rowe_newsgroups <rowe_em...@yahoo.comwrote:
Well.. I cannot store the button into the variable. I'm supposed to
only know the button name.
Is this a school assignment?
I see no other time when you're only "supposed to know" a button name.
Thanks,
Seth Rowe
On Apr 17, 12:44 pm, John Smith <I...@NETZERO.NETwrote:
Hi Rowe, thanks for replying.
Well.. I cannot store the button into the variable. I'm supposed to
only know the button name.
I've tried to set the variable as a string, then as an object, but so
far I can't get it right.
I really hope this could be as easy as what Tom suggested:
Me.Controls[TheName].Enabled = False
The problem is that whenever I use the me. part, I get an error saying
that the variable is not a member of my form.
Is there a way to cast the variable as the button name using something
like DirectCast?
Thanks for all your help!- Hide quoted text -
- Show quoted text -
:-)
Yes, it is and it's driving me crazy!
Why can't you loop through the control collection or use a hash table?
In the future you should ask your professor/teacher or a fellow
student for help - this newsgroup is not here to do your homework!
Thanks,
Seth Rowe This discussion thread is closed Replies have been disabled for this discussion. Similar topics
7 posts
views
Thread by Gary |
last post: by
|
reply
views
Thread by Lokkju |
last post: by
|
1 post
views
Thread by ratnakarp |
last post: by
|
2 posts
views
Thread by John Regan |
last post: by
|
3 posts
views
Thread by Brett Wesoloski |
last post: by
| | | | | | | | | | | | | | |