Hi,
Following code i have written is doing exactly what you asked for.In this
code there is one datagridview,one button called btnCopyToClipBoard to copy
content of current cell to clipboard,another button called
btnDisplayClipBoardData to display data fron clipboard.:
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
DataTable dt = new DataTable();
DataColumn col = new DataColumn();
col.DataType = typeof(System.String);
DataColumn col1 = new DataColumn();
col1.DataType = typeof(System.String);
dt.Columns.Add(col);
dt.Columns.Add(col1);
DataRow dr1 = dt.NewRow();
DataRow dr2 = dt.NewRow();
dr1[0] = "Manish";
dr1[1] = "Bafna";
dt.Rows.Add(dr1);
dr2[0] = "Sanjay";
dr2[1] = "Bafna";
dt.Rows.Add(dr2);
dt.AcceptChanges();
dataGridView1.DataSource = dt;
}
private void btnDisplayClipBoardData_Click(object sender, EventArgs e)
{
IDataObject iData = Clipboard.GetDataObject();
//Determine whether the data is in a format you can use.
if (iData.GetDataPresent(DataFormats.Text))
{
string str = (String)iData.GetData(DataFormats.Text);
MessageBox.Show(str);
}
}
private void btnCopyToClipBoard_Click(object sender, EventArgs e)
{
//the second parameter indicates that data copied to clipboard will remain
//there even after one exists application
Clipboard.SetDataObject(dataGridView1.CurrentCell.Value.ToString(),true);
}
}
}
please do let know if this is what you were looking for.Have a nice day.
--
Hope this helps.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.
Juan Dent said:
Hi,
I have a DataGridView from Windows.Forms and need to be able to copy the
contents of the current cell to the clipboard, yet have not found the way to
do so.
Any pointers will be very appreciated.