Dev GridView 右键复制单元格内容

--先给GridView控件注册鼠标按下事件
gv.MouseDown += new System.Windows.Forms.MouseEventHandler(this.gv_MouseDown); --在鼠标按下事件里面增加鼠标右键判断,并增加鼠标右键菜单复制单元格功能。 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;
--获取单元格内容 string copiedData = (sender as GridView).GetRowCellDisplayText(gridHitInfo.RowHandle, gridHitInfo.Column); if (string.IsNullOrEmpty(copiedData)) return; --复制到剪贴板 Clipboard.Clear(); Clipboard.SetData(DataFormats.Text, copiedData); } }

你可能感兴趣的:(Dev GridView 右键复制单元格内容)