473,399 Members | 3,302 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Set enabled property of private field by name?

I am trying to locate a field (ToolStripMenuItem) by name in the current form
and set its Enabled property, but I'm having no luck (skill) so far.

Any help you could provide wold be greatly appreciated.

This is the code I have so far. The line using (ToolStripMenuItem field =
GetField(name)) is where I need to grab a reference to the field to affect,
and obviously the existing code is not correct, but it should give you the
idea.

private void SetSecurityOnMenu()
{
string name = String.Empty;
Constants.GUIObjectRestrictions restriction =
Constants.GUIObjectRestrictions.None;

statusStrip1.Items[0].Text = "Setting security on menu items...";

// Get the list of objects on this form that have restrictions
ArrayList l =
BL.SecuredGUIObjectRestrictions.GetSecuredGUIObjec tRestrictionsForParent(this.Name, Common.CommaDelimitedSecurityGroupList(MyPrincipal ));

for (int i = 0, limit = l.Count; i < limit; i++)
{
name = ((GUIObjectRestrictions)l[i]).ObjectName;
restriction = ((GUIObjectRestrictions)l[i]).Restriction;
using (ToolStripMenuItem field = GetField(name))
{
if (restriction == Constants.GUIObjectRestrictions.Disable)
{
field.Enabled = false;
}
}
}
statusStrip1.Items[0].Text = String.Empty;
}

Jun 21 '06 #1
2 1824
That's actually the path I started down, but I was having trouble with it,
mainly because of the recursion required with submenus. Then I decided that
since the menus only had to be set up once and the disabled items would be
the exception it might just be faster to hit the menu item fields actually
needed to be disabled rather than traversing all of them.

"Peter Ritchie" wrote:
Why not just traverse the Items property of the MenuStip to which the menu
item(s) is associated with?

--
http://www.peterRitchie.com/
"Byron" wrote:
I am trying to locate a field (ToolStripMenuItem) by name in the current form
and set its Enabled property, but I'm having no luck (skill) so far.

Any help you could provide wold be greatly appreciated.

This is the code I have so far. The line using (ToolStripMenuItem field =
GetField(name)) is where I need to grab a reference to the field to affect,
and obviously the existing code is not correct, but it should give you the
idea.

private void SetSecurityOnMenu()
{
string name = String.Empty;
Constants.GUIObjectRestrictions restriction =
Constants.GUIObjectRestrictions.None;

statusStrip1.Items[0].Text = "Setting security on menu items...";

// Get the list of objects on this form that have restrictions
ArrayList l =
BL.SecuredGUIObjectRestrictions.GetSecuredGUIObjec tRestrictionsForParent(this.Name, Common.CommaDelimitedSecurityGroupList(MyPrincipal ));

for (int i = 0, limit = l.Count; i < limit; i++)
{
name = ((GUIObjectRestrictions)l[i]).ObjectName;
restriction = ((GUIObjectRestrictions)l[i]).Restriction;
using (ToolStripMenuItem field = GetField(name))
{
if (restriction == Constants.GUIObjectRestrictions.Disable)
{
field.Enabled = false;
}
}
}
statusStrip1.Items[0].Text = String.Empty;
}

Jun 21 '06 #2
Hi,
Unless you have an unusual amount of menues I would go this way. This
method will be good even if at some point you decide to add menuitems by
code.
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Byron" <By***@discussions.microsoft.com> wrote in message
news:81**********************************@microsof t.com...
That's actually the path I started down, but I was having trouble with it,
mainly because of the recursion required with submenus. Then I decided
that
since the menus only had to be set up once and the disabled items would be
the exception it might just be faster to hit the menu item fields actually
needed to be disabled rather than traversing all of them.

"Peter Ritchie" wrote:
Why not just traverse the Items property of the MenuStip to which the
menu
item(s) is associated with?

--
http://www.peterRitchie.com/
"Byron" wrote:
> I am trying to locate a field (ToolStripMenuItem) by name in the
> current form
> and set its Enabled property, but I'm having no luck (skill) so far.
>
> Any help you could provide wold be greatly appreciated.
>
> This is the code I have so far. The line using (ToolStripMenuItem
> field =
> GetField(name)) is where I need to grab a reference to the field to
> affect,
> and obviously the existing code is not correct, but it should give you
> the
> idea.
>
> private void SetSecurityOnMenu()
> {
> string name = String.Empty;
> Constants.GUIObjectRestrictions restriction =
> Constants.GUIObjectRestrictions.None;
>
> statusStrip1.Items[0].Text = "Setting security on menu items...";
>
> // Get the list of objects on this form that have restrictions
> ArrayList l =
> BL.SecuredGUIObjectRestrictions.GetSecuredGUIObjec tRestrictionsForParent(this.Name,
> Common.CommaDelimitedSecurityGroupList(MyPrincipal ));
>
> for (int i = 0, limit = l.Count; i < limit; i++)
> {
> name = ((GUIObjectRestrictions)l[i]).ObjectName;
> restriction = ((GUIObjectRestrictions)l[i]).Restriction;
> using (ToolStripMenuItem field = GetField(name))
> {
> if (restriction ==
> Constants.GUIObjectRestrictions.Disable)
> {
> field.Enabled = false;
> }
> }
> }
> statusStrip1.Items[0].Text = String.Empty;
> }
>

Jun 21 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: David Elliott | last post by:
I am looking to use a field attribute in a to find and use a property. If given Find("Record Artist", "Billy Joel"); I am looking to find the first instance in the collection where the value the...
2
by: HolaGoogle | last post by:
Hi all, Can you please tell me what's wrong with my code??? i do have this database in wich i have to field.One is a "yes/no" field and another one is "number" field. To display the yes/no field...
2
by: Andrzej Kaczmarczyk | last post by:
Hi, I have following problem: (warning, quite long post with lots of code) I have an object of a known type like this. class MyClass { public int Property1; public string Property2; }
5
by: Leo J. Hart IV | last post by:
Hello, I'm hoping someone can help me out. I was wondering if the Enabled property of a CheckBox or RadioButton server control is stored in the ViewState. If not, is there some way to to add...
4
by: Phill. W | last post by:
Here's a knotty little problem. I have some nasty little controls that needs to behave in a non- windows-Standard way - don't ask why; it's a large application being converted from some older...
62
by: djake | last post by:
Someone can explain me why to use property get and property set to access a value in a class, insted of access the value directly? What's the usefulness of property statements in VB.NET? Thanks
9
by: Stefan De Schepper | last post by:
Should I use: Private m_Name As String Public Property Name() As String Get Return m_Name End Get Set(ByVal Value As String) m_Name = Value
7
by: Curious | last post by:
Hi, I have a C# class that contains a property defined as follows: public bool bRunTwice { get { return bRunTwice; } set { bRunTwice = value; } }
0
by: tschroeder250 | last post by:
Hi Everyone, There are so many Nullable DateTimePickers out there that this post may not even be found among all the others, but I wanted to try. First, I want to thank all the authors of the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.