We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Different right click menus for different cells

Hi,

Does anyone know of a way to customize the right click menus based on cell position and values?

For example, lets say we have employee-task grid with columns for employees and rows for tasks. If I right click on Employee Name cell, it would display employee related menus. If I right click on Task Name cell, it should display Task related menus.

Thanks,

Puspal

Hi,

Please see the demo “CustomContextMenu .aspx/cs” in our featured demos for Aspose.Cells.GridWeb. The featured demo solutions are installed on your installation folders when you use Aspose.Cells.msi installer to install the product on your machine. So, you may open the Aspose.Cells.GridWeb demo solutions in your VS.NET and get reference.

Thank you.

Hi Amjad,

Thanks for your reply. I checked the CustomContextMenu .aspx demo but that didn't answer my question. In the demo, it is changing the value of cell based on commands.

But I want different command menus for different cells

For example: when I right click on employee name cell, it would display the following menue:

Update Employee

Delete Employee

When I right click on taskname cell, it would display the following menus:

Update Task Details

Delete Task

Split Taks

Thanks,

Puspal

Hi,

Thanks for your understanding.

The feature you described is not currently available.

We will work on this feature and try to incorporate it in the new release or in a hot fix.

We will soon update you about the anounement.

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you.

Hi Salman,

Thanks for your reply.

I am glad to know that you can incorporate the feature in the new release or in hot fix.

This is very critical for our project. We will be waiting for your fix. Please can you tell me an approximate date when you can provide us the fix.

Thanks,

Puspal

Hi,

Please try the attached version of Aspose.Cells.GridWeb. We provide a property named OnContextMenuShowClientFunction in Aspose.Cells.GridWeb v2.3.0.2002(attached). You can set visibilities of context menu items at client side script function (OnContextMenuShowClientFunction) when the context menu will be shown.

Please try the source files in the attached archive with Aspose.Cells.GridWeb v2.3.0.2002 (attached). It can suit your requirement.

Thank you.

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

I really appreciate your quick response. I am able to change the visibilities of context menus using your solution.

But I also need to change the TEXT of the menu. For example, if I click on Employee1, it would display "Edit Employee1"; for Employee2, it would be "Edit Employee2".

Please can you suggest me, how to change the Context Menu TEXT dynamically from JavaScript.

Also I have removed the default context menus but could not remove the blank space and 2 lines from top (please see the attached screenshot).

Is there any way to remove those 2 lines at and spaces from top of the context menu box?

Thanks,

Puspal

Hi,


Please try the following scripting lines, it can suit your requirements.

function onContextMenuShow()
{
var menu = event.srcElement;
var cell = menu.menuContext;
if (cell == null)

cell = GridWeb1.getActiveCell();

if (cell == null)

{

menu.hide();

return;

}



var value = GridWeb1.getCellValueByCell(cell);

if (value ==
“Employee1”)

{

menu.clear();

// The prefix “CCMD:” indicates this is a custom command which will
fire the CustomCommand event.

menu.addItem(“Update Employee1”, “CCMD:Update Employee”);

}

else if (value
== “Employee2”)

{

menu.clear();

menu.addItem(“Update Employee2”, “CCMD:Update Employee”);

}

else if (value
== “Task1”)

{

menu.clear();

menu.addItem(“Update Task1”, “CCMD:Update Task Details”);

menu.addSeparator();

menu.addItem(“Delete Task1”, “CCMD:Delete Task”);

}

else if (value
== “Task2”)

{

menu.clear();

menu.addItem(“Update Task2”, “CCMD:Update Task Details”);

menu.addSeparator();

menu.addItem(“Delete Task2”, “CCMD:Delete Task”);

}

else

{

menu.hide();

}

}

<o:p></o:p>

Thank you.

Hi Amjad,

Thanks for your suggestion. That helped me to create different right click menus.

Now I need your help again on the event handlers.

1) I am using OnCustomCommand for server side event handler. I need to access the row & column number of the selected cell( where I right clicked) at server side. Please suggest how to access the row and column index of the selected cell.

2) After handling the event at server side, I need to put some value on the selecetd cell without refreshing the whole gird. I tried using cell[x,y].putvalue method but its not working if I enable the AJAX.

If I disable the AJAX, then its creating a new grid and the original grid is lost. Please suggest how to put value in cell without refreshing the whole grid.

Thanks,

Puspal

Hi,

We will get back to you soon for your queries.

Thank you.

Hi Puspal,

1. You can get the selected cell via GridWeb.ActiveCell property at server side.

2. Some behaviors (like: insert row, change sheet and custom command etc.) need re-render gridweb control. So, the whole grid will be refreshed. When EnableAJAX is set to true, the page will not be refreshed. We tried the following code in EnableAJAX = true. It works fine.
protected void GridWeb1_CustomCommand(object sender, string command)
{
switch (command)
{
case "Update Employee":
WebWorksheet sheet = GridWeb1.WebWorksheets[0];
sheet.Cells["d4"].PutValue(GridWeb1.ActiveCell.Value.ToString() + ", naa");
break;
}
}

Thanks,