Dev GridView 右键复制单元格内容

Posted on 2020-07-08 10:53  haishu  阅读(162)  评论(0编辑  收藏
--先给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); } }

posts - 77, comments - 23, trackbacks - 0, articles - 0

Copyright © 2020 haishu
Powered by .NET Core on Kubernetes