473,396 Members | 1,915 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,396 software developers and data experts.

How to dynamically control mdi menu c#.Net

4
Hi Dear All,

I create a window application in c#.net. I want to hide menu options when particular user login for example: in mdi menu there is Report menu there is report1 and report2 now when user1 login I want to show all option report1 and report2 but when user2 login I want to show only report1.

In vb6 it is very essay but because I am new in c#.net I couldn’t find the solution.
Please help me to find the solution.

Thanks and Regards
Prakash
Oct 1 '09 #1
7 8957
GaryTexmo
1,501 Expert 1GB
You should just be able to set the tool strip item's visible property to false. I just tested it and it appears to work.
Oct 1 '09 #2
ppaul4
4
fine here is the code

foreach (ToolStripMenuItem tsmi in menuStrip.Items)
{
if (tsmi.Text == "Security")
{
/// some code
}
}

in mdi load i call user login form, now as per user permission i want to hide/unhide the menu options

problem
1. this code is work f9 when i put this in mdi load but in user form it will return null object reference.
2. it only return the mater menu like only file option not files child node

please help or provide some code

problem
Oct 1 '09 #3
GaryTexmo
1,501 Expert 1GB
I don't understand what the problem is... is it that you can't hide/show menu selections, or that you're getting a null reference exception when you run?
Oct 1 '09 #4
ppaul4
4
I am getting null reference
Oct 2 '09 #5
GaryTexmo
1,501 Expert 1GB
Where are you hitting the null reference? If you're using Visual Studio, you should be able to run it in debug mode (F5) and it will break where the exception is thrown.

From the code you posted, the only place I can see a null reference occurring is menuStrip, but you've given no context so I can't tell why it would be null.

You mentioned that it doesn't work when you put it in the user form... I don't know what that is with respect to your code, but make sure it knows what menuStrip is, or has it initialized.
Oct 2 '09 #6
ppaul4
4
/// Application start from here
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
Application.Run(new MDIColts ());
}

/// MDI load code having no problem
/// menuStrip is private System.Windows.Forms.MenuStrip menuStrip;

private void MDIColts_Load(object sender, EventArgs e)
{
foreach (ToolStripMenuItem tsmi in menuStrip.Items)
{
if (tsmi.Text == "Security" || tsmi.Text == "Master" || tsmi.Text == "Transactions" || tsmi.Text == "Reports")
{
getChildNodes(tsmi);

}
}

MasterUI.frmLogin.GetInstance.ShowDialog();
}

///the time of MDI load I call MasterUI.frmLogin.GetInstance.ShowDialog();
/// and in the click of user login
private void btLogin_Click(object sender, EventArgs e)
{
try
{
if (UserLogIn.bActive == false)
{
MessageBox.Show(MessageResource.NotActive, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
txtUserId.Text = "";
txtPassword.Text = "";
txtUserId.Focus();
}
else
{
/// code where collecting data from database , security table and as per permissions want to show mdi menu items
///menuStrip.Items null ref problem
foreach (ToolStripMenuItem tsmi in menuStrip.Items)
{
if (tsmi.Text == "Security" || tsmi.Text == "Master" || tsmi.Text == "Transactions" || tsmi.Text == "Reports")
{

}
}


if you have any good suggestion or help please provide me
Oct 2 '09 #7
GaryTexmo
1,501 Expert 1GB
In the future, can you please use code tags when you post? It makes it a lot easier to read. You can find some information here: http://bytes.com/misc.php?do=bbcode

Anyway, so the btLogin_Click method is in the user form, right? It looks like you're trying to access the main form's menuStrip from the child form... you shouldn't even be able to see that because it's private.

I realize this might be something to do with MDI (which I don't have any experience with), but I'll still try to help you out if I can.

Basically, how are you accessing menuStrip from the user form when it actually belongs to the main form? Is there some way to access the user form's parent so you can get a hold of the parent's menu strip?

That said, a better approach might be to have the user form return a login status and let the parent form show or hide it's own menu items. It would better avoid confusion like this.
Oct 2 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Gopal Krish | last post by:
I'm have coded a simple menu (using link buttons as menu items) in a user control to be reused across many ASPX pages. In the page_load method I dynamically create the link buttons as follows ...
0
by: Dan | last post by:
hi, i have a page with two usercontrols: 1. a static menu control. 2. a dynamically loaded control as user interface the main page receives events from the menu and sets the apropriate ui...
2
by: jack | last post by:
Hello, I need to dynamically add menu items to an existing menu on an MDI form. In the form load, when I create the menu items then add it to the menu control using the Add method, the entire...
12
by: nat | last post by:
Hi all, I was going to post this in the AJAX forum, but apparently someone posted an AJAX/C# question in there today and was told to try this forum instead. So here goes: I'm trying to figure...
7
by: Steve_Black | last post by:
Hello, I'm toying with the idea of loading a MenuStrip (VB.Net 2005) dynamically based on who is logged into my system. Every user has different security settings and I want to customize the...
0
by: Jose Walker | last post by:
Hi there! I've been fighting with an issue that by now is driving me crazy. I've developed a ASP.NET 2 web part from which I build dynamically an ASP.NET 2 Menu control, I populate the control...
0
by: John Smith | last post by:
I still have not gotten this damn thing figured out and I'm asking for help one last time before I give up on it. I have a user control that contains a paged gridview control. The master page...
2
by: John Haycock | last post by:
Hi All I have a user control that uses a repeater to build a list of menu links: <itemtemplate> <li> <a href='news.aspx?newsID=<%# DataBinder.Eval(Container.DataItem,"newsID") %>'> <%#...
23
by: LvBohemian | last post by:
I am playing around with creating some menus dynamically, and they create fine and show up ok when I want them to; but when I select a menu NavigateUrl at run time, the applicable url shows up...
0
by: Puja | last post by:
hi all, I have asp.net menu control on my page. I want to hide some menu and sub-menu items dynamically depending on user. (i.e after user is logged in) is there any property like ...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.