Dev GridView right click to copy cell contents

Time:2020-9-24
--First register the mouse down event for the GridView control gv.MouseDown  += new  System.Windows.Forms .MouseEventHandler( this.gv_ MouseDown);
--Add the right mouse button judgment in the event of mouse down, and add the function of cell copy by right mouse button menu.
 private void gv_MouseDown(object sender, MouseEventArgs e)
 {
            if (e.Button == MouseButtons.Right)
            {
                GridHitInfo gridHitInfo = new GridHitInfo();
                Point point = new Point(e.X, e.Y);
                gridHitInfo = (sender as GridView).CalcHitInfo(point);
                if ( gridHitInfo.Column  ==Null) return; -- get cell content
                string copiedData = (sender as GridView).GetRowCellDisplayText(gridHitInfo.RowHandle, gridHitInfo.Column);
                if (string.IsNullOrEmpty(copiedData)) return;
                --Copy to clipboard
                Clipboard.Clear();
                Clipboard.SetData(DataFormats.Text, copiedData);
            }
  }