Print Page | Close Window

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

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=535
Printed Date: 11-Jun-2026 at 1:38pm


Topic: How can I enable/disable toolbar specific items in a GridView within a Tab.
Posted By: alejandro
Subject: How can I enable/disable toolbar specific items in a GridView within a Tab.
Date 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.




Replies:
Posted By: Bill Jensen
Date 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


Posted By: alejandro
Date 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


Posted By: Bill Jensen
Date 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;

}




Print Page | Close Window