New Posts New Posts RSS Feed: How can I enable/disable toolbar specific items in a GridView within a Tab.
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

How can I enable/disable toolbar specific items in a GridView within a Tab.

 Post Reply Post Reply
Author
alejandro View Drop Down
Newbie
Newbie
Avatar

Joined: 14-Jun-2007
Location: Netherlands Antilles
Posts: 10
Post Options Post Options   Quote alejandro Quote  Post ReplyReply Direct Link To This Post Topic: How can I enable/disable toolbar specific items in a GridView within a Tab.
    Posted: 06-Nov-2007 at 6:56am
How can I enable/disable toolbar specific items in a GridView within a Tab.
The ChildGridViewContext only provides me with the ability to make the complete toolstrip visible or invisible. ChildGridViewContext.GridViewToolStripVisible
 
I am doing it in the Summary View's page controller using code like the following. The idea is based on current user's properties enable/disable the toolstrip items:

protected override void BuildCore()

{ base.BuildCore();

ApplyAuthorizationToPageToolBar();

}

private void ApplyAuthorizationToPageToolBar()

{

///Enable/disable toolbar items according to authorization.

if (User.CurrentUserCanCreate(HRIS.Model.UI.GetById(OrganizationMainUIIdValue)))

{PageToolBar.AddNewItemEnabled = true;}

else{PageToolBar.AddNewItemEnabled = false;}

}

 

I want to do something similar for the grid in the tab but don't know how.

Back to Top
Bill Jensen View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 31-Jul-2007
Location: United States
Posts: 229
Post Options Post Options   Quote Bill Jensen Quote  Post ReplyReply Direct Link To This Post Posted: 13-Nov-2007 at 11:09am
Hello Alejandro,
 
Sorry to not reply sooner.  Something went wrong with my e-mail notification of forum posts last week.
 
The DotNetNavigatorGridViewToolStripAdapter attaches commands to the buttons and registers them in the workitem.  The button visibility depends on the command's status, so try this:
 

using IdeaBlade.Cab.Interface.Constants;

using Microsoft.Practices.CompositeUI.Commands;

void EnableAddNew()

{

string commandName = viewContext.MakeViewSpecificId(CommandNames.AddNew);

Command cmd = WorkItem.Commands.Get(commandName);

cmd.Status = CommandStatus.Enabled;

}

void DisableAddNew()

{

string commandName = viewContext.MakeViewSpecificId(CommandNames.AddNew);

Command cmd = WorkItem.Commands.Get(commandName);

cmd.Status = ommandStatus.Unavailable;

}

There are also a number of static functions in IdeaBlade.Cab.Interface.Miscellaneous.CabFns that encapsulate some of this.

Let me know if this helps.
 
Bill Jensen
IdeaBlade
Back to Top
alejandro View Drop Down
Newbie
Newbie
Avatar

Joined: 14-Jun-2007
Location: Netherlands Antilles
Posts: 10
Post Options Post Options   Quote alejandro Quote  Post ReplyReply Direct Link To This Post Posted: 15-Nov-2007 at 12:06pm
Hello Bill, 
 
Thanks for the response.
 
I tried it in the override of the ChildTabViewController's ConfigureViewContext method and it works fine.
The only thing is that the toolitem does not turn gray. You can click on it and nothing happens(as desired) but the color of the Add New button remains yellow even if I made the CommandStatus.Disabled.
 
Any idea of what am I missing?
 
Thanks a lot,
Alejandro
Back to Top
Bill Jensen View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 31-Jul-2007
Location: United States
Posts: 229
Post Options Post Options   Quote Bill Jensen Quote  Post ReplyReply Direct Link To This Post Posted: 15-Nov-2007 at 3:57pm
Not immediately. 
 
Here's my code (from my child TabViewController) that seems to work OK.  The AddNew button is visible but grayed out.
 
Is your code different in some way?

/// <summary>Create the view and add it to WorkItem SmartParts.</summary>

public override void CreateView()

{

mBindingSource = new EntityBindingSource(typeof(Order), EntityManager, mEmptyList, String.Empty);

ViewId = "EmployeeOrders";

mContext = GridViewContext.AddNew(WorkItem, ViewId, mBindingSource);

mContext.GridViewToolStripVisible = true;

View = ViewFactory.AddNew(Constants.ViewNames.BasicGrid, WorkItem, ViewId, typeof(Order));

AddCommandHandler();

DisableAddNew();

}

void AddCommandHandler()

{

string commandName = mContext.MakeViewSpecificId(CommandNames.AddNew);

Command cmd = WorkItem.Commands.Get(commandName);

cmd.ExecuteAction += new EventHandler(cmd_ExecuteAction);

}

void cmd_ExecuteAction(object sender, EventArgs e)

{

System.Windows.Forms.MessageBox.Show("Add New Button Clicked");

}

void EnableAddNew()

{

string commandName = mContext.MakeViewSpecificId(CommandNames.AddNew);

Command cmd = WorkItem.Commands.Get(commandName);

cmd.Status = CommandStatus.Enabled;

}

void DisableAddNew()

{

string commandName = mContext.MakeViewSpecificId(CommandNames.AddNew);

Command cmd = WorkItem.Commands.Get(commandName);

cmd.Status = CommandStatus.Disabled;

}

void HideAddNew()

{

string commandName = mContext.MakeViewSpecificId(CommandNames.AddNew);

Command cmd = WorkItem.Commands.Get(commandName);

cmd.Status = CommandStatus.Unavailable;

}

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down