Click here to Skip to main content
15,906,574 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a menu bar and their items are
item1
item2
item3
.
.
.

initally all items visibility is false

in an arraylist these items are saved

e.g.
in arraylist i have item1, item2, item3, ........
C#
for(int i=0; i<arraylist.count; i++) 
   arraylist[i].toString() 

now here the string is same as menubar item1
now from this array list i want to change the visibility of items
Posted
Updated 3-Aug-11 21:48pm
v4
Comments
[no name] 4-Aug-11 3:38am    
Please reframe your question what you want to ask. and share your code as well.

private void formm_display_function(string display_form_str)
{
   try
   {
      if(menuStrip1.Items.ContainsKey(display_form_str))
         menuStrip1.Items[display_form_str].Visible = true;
   }
   catch (Exception ex)
   {
      MessageBox.Show(ex.Message.ToString());
   }
}
 
Share this answer
 
v5
Comments
kami124 4-Aug-11 4:10am    
ok when this condition will become true
if (ctrl.Length == 1)
UJimbo 4-Aug-11 4:13am    
When Contols.Find "finds" at least 1 control having the same name as the item parameter. For example, in my case, I have a listview control on my form named "listview1". Controls.Find will return only 1 control in the ctrl array.
kami124 4-Aug-11 4:15am    
here is my actual code check where i make a mistake

private void formm_display_function(string display_form_str)
{

// string[] theArr = new string[] { "listView1" };

// foreach (string item in function_list_display)
for (int i = 0; i < function_list_display.Count; i++)
{
Control[] ctrl = this.Controls.Find(function_list_display[i], false);

if (ctrl.Length == 1)
{
ctrl[0].Visible = true;
}
}
}
kami124 4-Aug-11 4:15am    
private void formm_display_function(string display_form_str)
{


for (int i = 0; i < function_list_display.Count; i++)
{
Control[] ctrl = this.Controls.Find(function_list_display[i], false);

if (ctrl.Length == 1)
{
ctrl[0].Visible = true;
}
}
}
UJimbo 4-Aug-11 4:23am    
You don't need to use an array list in this function by the looks of it, since you are only supplying a string parameter called display_form_str. If this is correct, just use:

private void formm_display_function(string display_form_str)
{
Control[] ctrl = this.Controls.Find(display_form_str, false);

if (ctrl.Length == 1)
{
ctrl[0].Visible = true;
}
}
If your ArrayList contains the items - which it appears to - then just cast them to ToolStripMenuItems and set the appropriate properties.

Or better, don't use an ArrayList, use a List<ToolStripMenuItem> instead, and you won't need to cast it...
 
Share this answer
 
Try this.
for(int i=0; i<arraylist.count; i++) 
{
  if(arraylist[i].toString() == "item1")
  {
    item1Id.Visible = true;
  }
  else if(arraylist[i].toString() == "item2")
  {
    item2Id.Visible = true;
  }
  else if(arraylist[i].toString() == "item3")
  {
    item3Id.Visible = true;
  }
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900