在单元格点右键【复制单元格】:
解决方案:
1. 在界面添加一个ContextMenuStrip组件,如ContextMenuStrip1
2. GridControl.ContextMenuStrip属性设置为ContextMenuStrip1
复制单元格Click事件:
C# Code:
private void 复制单元格ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (gvDetail.RowCount > 0 && gvDetail.FocusedColumn != null && gvDetail.FocusedRowHandle >= 0)
{
string data = gvDetail.GetFocusedRowCellDisplayText(gvDetail.FocusedColumn);
if (!String.IsNullOrEmpty(data))
Clipboard.SetText(data, TextDataFormat.Text);
}
}
//来源:C/S框架网(www.csframework.com) QQ:23404761
private void 复制单元格ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (gvDetail.RowCount > 0 && gvDetail.FocusedColumn != null && gvDetail.FocusedRowHandle >= 0)
{
string data = gvDetail.GetFocusedRowCellDisplayText(gvDetail.FocusedColumn);
if (!String.IsNullOrEmpty(data))
Clipboard.SetText(data, TextDataFormat.Text);
}
}
//来源:C/S框架网(www.csframework.com) QQ:23404761
弹出菜单Opening事件可控制菜单项以及是否弹窗菜单:
C# Code:
private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
{
e.Cancel = !this.IsAddOrEditMode;
if (this.IsAddOrEditMode)
{
DataRow row = gvDetail.GetFocusedDataRow();
if (row == null || gvDetail.FocusedColumn == null)
{
e.Cancel = true;
return;
}
复制单元格ToolStripMenuItem.Enabled = row != null; } }
private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
{
e.Cancel = !this.IsAddOrEditMode;
if (this.IsAddOrEditMode)
{
DataRow row = gvDetail.GetFocusedDataRow();
if (row == null || gvDetail.FocusedColumn == null)
{
e.Cancel = true;
return;
}
复制单元格ToolStripMenuItem.Enabled = row != null; } }