This is a migrated thread and some comments may be shown as answers.

Right Click on ContextMenu will trigger OnRowDragStarted

1 Answer 79 Views
Grid
This is a migrated thread and some comments may be shown as answers.
jing
Top achievements
Rank 1
jing asked on 22 Nov 2010, 05:06 AM
I have the RadGrid with drag and drop function and context menu. When I select multiple rows and right click, the context menu shown and the "no access" cursor is also appear (change of "no access" cursor is in ongriddragstarted event).

How do I stop triggering the OnRowDragStarted when right click on the selected multiple rows? Thanks!!

aspx:
<%@ Page Language="C#" AutoEventWireup="true" Codebehind="Default.aspx.cs" Inherits="Default" %>
  
<html>
<head runat="server">
    <title></title>
    <style type="text/css">
    .noAccessCursor, .noAccessCursor *
    {
        cursor:url('noaccess.cur'), default !important;
    }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager" runat="server" />
        <telerik:RadScriptBlock runat="server" ID="ScriptBlock">
  
            <script type="text/javascript">
            function gridRowContextMenu(sender, args)
            {
                // remove the cursor cause but the onrowdragstarted
                Sys.UI.DomElement.removeCssClass(document.documentElement, "noAccessCursor");
                  
                var evt = args.get_domEvent();
                if(evt.target.tagName == "INPUT" || evt.target.tagName == "A") 
                    return;
                      
                var menu = $find("<%= ContextMenu1.ClientID %>");
                  
                menu.show(evt);
  
                //evt.cancelBubble = true;
                //evt.returnValue = false;
  
                //if (evt.stopPropagation)
                //{
                //    evt.stopPropagation();
                //    evt.preventDefault();
                //} 
            }
  
            var destTaxonomyID;
            //var expandedNodes = [];
            function gridRowDropping(sender, args) 
            {
                args.set_cancel(true);
                alert("Dropped");
                  
                // reset the cursor to default
                Sys.UI.DomElement.removeCssClass(document.documentElement, "noAccessCursor");
            }
  
            function gridRowDragStarted(sender, args)
            {
                Sys.UI.DomElement.addCssClass(document.documentElement, "noAccessCursor");
            }
            </script>
  
        </telerik:RadScriptBlock>
        <telerik:RadContextMenu ID="ContextMenu1" runat="server" Skin="Vista">
            <Items>
                <telerik:RadMenuItem Text="Menu 1" />
                <telerik:RadMenuItem Text="Menu 2" />
            </Items>
            <Targets>
                <telerik:ContextMenuControlTarget ControlID="GridDocument" />
            </Targets>
        </telerik:RadContextMenu>
        <telerik:RadGrid ID="Grid1" runat="server" AutoGenerateColumns="False" Skin="Vista"
            AllowPaging="True" AllowSorting="True" AllowMultiRowSelection="true" GridLines="None"
            Width="100%" Height="345px" BorderWidth="0px" OnRowDrop="Grid1_RowDrop">
            <PagerStyle AlwaysVisible="true" Mode="NextPrevAndNumeric" />
            <MasterTableView DataKeyNames="ID" ClientDataKeyNames="ID" TableLayout="Fixed">
                <Columns>
                    <telerik:GridBoundColumn DataField="Title" HeaderText="Title" UniqueName="Title">
                    </telerik:GridBoundColumn>
                </Columns>
            </MasterTableView>
            <ClientSettings EnableRowHoverStyle="True" AllowRowsDragDrop="true">
                <Selecting AllowRowSelect="True"></Selecting>
                <ClientEvents OnRowContextMenu="gridRowContextMenu" OnRowDropping="gridRowDropping"
                    OnRowDragStarted="gridRowDragStarted" />
                <Scrolling AllowScroll="true" UseStaticHeaders="true" />
                <Resizing AllowColumnResize="True" EnableRealTimeResize="true" ClipCellContentOnResize="true">
                </Resizing>
            </ClientSettings>
        </telerik:RadGrid>
    </form>
</body>
</html>

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;
  
public partial class Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DataTable tb = new DataTable();
            tb.Columns.Add("ID");
            tb.Columns.Add("Title");
  
            for (int i = 0; i < 10; i++)
            {
                DataRow row = tb.NewRow();
                row["ID"] = i;
                row["Title"] = "Title " + i;
                tb.Rows.Add(row);
            }
  
            Grid1.DataSource = tb;
            Grid1.DataBind();
        }
    }
  
    protected void Grid1_RowDrop(object sender, GridDragDropEventArgs e)
    {
  
    }
}

1 Answer, 1 is accepted

Sort by
0
Accepted
Dimo
Telerik team
answered on 24 Nov 2010, 04:23 PM
Hi Jing,

You can override the internal RadGrid functionality. Please add the following Javascript to the <body> of your web page (you can include it in an external JS file, but it must be registered in the <body>).

Telerik.Web.UI.RadGrid.prototype._mouseDownOld = Telerik.Web.UI.RadGrid.prototype._mouseDown;
Telerik.Web.UI.RadGrid.prototype._mouseDown = function(e)
{
    if (e.button != 0) // is not left button
    {
        return false;
    }
    else
    {
        this._mouseDownOld(e);
    }
}


Kind regards,
Dimo
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
jing
Top achievements
Rank 1
Answers by
Dimo
Telerik team
Share this question
or