Navigation Bar; remove items at run-time.

0
0

I am trying to use the Navigation Bar but I have items in it I don’t want certain users to see certain options. I can set Visible = false but wanted to know if there was any way to remove them completely.

I’ve tried this.Controls.Remove() and navBar.Controls.Remove() and then navBar.Update() but they still show and generate run-time errors when clicked.

  • You must to post comments
0
0

Hi Neil,

you can use the Items collection of the NavigationBar to show/hide items.

this.navigationBar1.Items[1].Visible = false;

Best regards,
Frank

  • Neil Hoskins
    Thanks Frank – I wanted to remove them (I have one app being used internally and by clients and I didn’t want them going to F12 to see what’s going on and be able to see other options at all). There is a very remote chance of this happening so hiding will have to do for now.
  • Frank (ITG)
    Hi Neil, another option is to add only the items that are needed, i.e. populate the list of items dynamically depending on permissions etc. which is what I did in one of our projects. Best regards, Frank
  • Neil Hoskins
    Frank – that was my initial idea but I’m using the Visual Studio Icons extension and wanted an icon against each option – this meant more effort figuring out how to do that (I am under a lot of time pressure, like most developers). I’ll try the dispose() option as you’ve said above too. THANK YOU for your help on this.
  • Luca (ITG)
    Controls.Remove() also works well. But if you call navBar.Controls.RemoveAt() you are removing the root controls which are the title, the items container, the footer. You have to go deep into the hierarchy (see the NavigationBar source code in our Github repositories). That’s why using Items.Remove() or navigationBarItem1.Dispose() is easier.
  • You must to post comments
0
0

I tried this on our NavigationBar sample in https://wisej.com/examples/ (click on the github link):

 

this.panel1.Items.RemoveAt(0); // any variation
// or
this.panel1.Items[0].Dispose();

 

Do you get an error? It seems to work fine:

https://drive.google.com/file/d/1oFe8nuciSjkg6dzwOCgkCCKsckTW_Yah/view

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.