Hi,
I would like to copy Datagridview selected rows to clipboard and paste them in notepad or Microsoft Word. What is the best method to achieve this?
Thank you..
Hi,
I would like to copy Datagridview selected rows to clipboard and paste them in notepad or Microsoft Word. What is the best method to achieve this?
Thank you..
I use a Copy menu item. If you want to use Ctrl+C, then you'll have to implement keyboard events. Here is my code:
private void copyToolStripMenuItem_Click(object sender, EventArgs e)
{
foreach (Control myControl in tabControl1.SelectedTab.Controls)
{
if (myControl is DataGridView))
{
DataGridView tempdgv = (DataGridView)myControl;
DataObject dataObj = tempdgv.GetClipboardContent();
try
{
Clipboard.SetDataObject(dataObj, true);
}
catch (Exception ex)
{
// Do Something
}
finally
{
if (selectAllToolStripMenuItem.Checked)
{
selectAllToolStripMenuItem_Click(this, EventArgs.Empty);
}
}
}
}
}