原创datagridview动态绑定contextmenustrip,并复制单元格数据
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了原创datagridview动态绑定contextmenustrip,并复制单元格数据相关的知识,希望对你有一定的参考价值。
public class DGVCopy
{
public DataGridView DataGridViewCopy { get; set; }
public int X { get; set; }
public int Y { get; set; }
public void CopyData()
{
DataGridViewCopy.CellMouseClick += new DataGridViewCellMouseEventHandler(DataGridViewCopy_CellMouseClick);
}
void DataGridViewCopy_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.RowIndex >= 0)
{
if (e.Button == MouseButtons.Right )
{
DataGridViewCopy.CurrentCell = DataGridViewCopy.Rows[e.RowIndex].Cells[e.ColumnIndex];
ContextMenuStrip contextMenuStrip1 = new ContextMenuStrip();
contextMenuStrip1.Items.Add("复制");
contextMenuStrip1.Size = new Size(30, 30);
DataGridViewCopy.ContextMenuStrip = contextMenuStrip1;
contextMenuStrip1.Show(X,Y);
contextMenuStrip1.Click += new EventHandler(contextMenuStrip1_Click);
}
}
}
void contextMenuStrip1_Click(object sender, EventArgs e)
{
Clipboard.SetDataObject(DataGridViewCopy.GetClipboardContent().GetText().Trim());
}
}
以上是关于原创datagridview动态绑定contextmenustrip,并复制单元格数据的主要内容,如果未能解决你的问题,请参考以下文章
DataGridView绑定DataTable动态生成列 并且将列名中文显示
DataGridViewComboBoxColumn这个东西,要怎样动态生成,动态绑定数据呢???真的好郁闷,狗一样的微软