示例#1
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            try
            {
                base.OnMouseDown(e);
                hitTestInfo = this.HitTest(e.X, e.Y);
                DataGridViewHitTestType hitTestType = hitTestInfo.Type;

                if (this.Rows.Count < 1)
                {
                    if (this.ContextMenuStrip != null)
                    {
                        this.ContextMenuStrip = null;
                    }

                    return;
                }

                //If user clicks on blank space below grid, then remove the context menu
                if (hitTestInfo.Type == DataGridViewHitTestType.None || hitTestInfo.ColumnIndex != 1 ||
                    hitTestInfo.RowIndex == -1)
                {
                    this.ContextMenuStrip = null;
                    return;
                }

                if (e.Button == MouseButtons.Right)
                {
                    this.Rows[hitTestInfo.RowIndex].Selected = true;


                    if (hitTestType == DataGridViewHitTestType.Cell)
                    {
                        if (this.ContextMenuStrip == null)
                        {
                            BuildContextMenu();
                        }

                        this.ContextMenuStrip = m_deleteContextMenuStrip;
                    }
                }
            }
            catch (Exception oEx)
            {
                LoggingHelper.ShowMessage(oEx);
            }
        }
示例#2
0
        protected override void OnMouseDown(MouseEventArgs e)
        {
            try
            {
                base.OnMouseDown(e);
                hitTestInfo = this.HitTest(e.X, e.Y);
                DataGridViewHitTestType hitTestType = hitTestInfo.Type;

                if (this.Rows.Count < 1)
                {
                    if (this.ContextMenuStrip != null)
                        this.ContextMenuStrip = null;

                    return;
                }

                //If user clicks on blank space below grid, then remove the context menu
                if (hitTestInfo.Type == DataGridViewHitTestType.None || hitTestInfo.ColumnIndex!=1  ||
                     hitTestInfo.RowIndex == -1)
                {
                    this.ContextMenuStrip = null;
                    return;
                }

                if (e.Button == MouseButtons.Right)
                {
                    this.Rows[hitTestInfo.RowIndex].Selected = true;


                    if (hitTestType == DataGridViewHitTestType.Cell)
                    {
						
                        if (this.ContextMenuStrip == null)
                            BuildContextMenu();

                        this.ContextMenuStrip = m_deleteContextMenuStrip;
                    }
                }
            }
            catch (Exception oEx)
            {
                LoggingHelper.ShowMessage(oEx);   
            }
        }