本文整理汇总了C#中System.Windows.Forms.DataGridView.GetClipboardContent方法的典型用法代码示例。如果您正苦于以下问题:C# DataGridView.GetClipboardContent方法的具体用法?C# DataGridView.GetClipboardContent怎么用?C# DataGridView.GetClipboardContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.DataGridView
的用法示例。
在下文中一共展示了DataGridView.GetClipboardContent方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyToClipboard
public static void CopyToClipboard(DataGridView dgv)
{
//Copy to clipboard
DataObject dataObj = dgv.GetClipboardContent();
if (dataObj != null)
Clipboard.SetDataObject(dataObj);
}
示例2: GetClipboardContentsDisabled
public void GetClipboardContentsDisabled ()
{
using (DataGridView dgv = new DataGridView ()) {
dgv.ClipboardCopyMode = DataGridViewClipboardCopyMode.Disable;
object o = dgv.GetClipboardContent ();
}
}
示例3: Copy
public static void Copy(DataGridView dgv)
{
dgv.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText;
DataObject d = dgv.GetClipboardContent();
if (d != null)
{
Clipboard.SetDataObject(d);
Clipboard.GetData(DataFormats.Text);
IDataObject dt = Clipboard.GetDataObject();
if (dt.GetDataPresent(typeof(string)))
{
String tb = (string)(dt.GetData(typeof(string)));
Encoding encoding = Encoding.GetEncoding(1251);
byte[] dataStr = encoding.GetBytes(tb);
Clipboard.SetDataObject(encoding.GetString(dataStr));
}
}
}
示例4: generate_case
static private void generate_case (StringBuilder result, DataGridView dgv, string message, bool headers)
{
Console.WriteLine (message + ", current length: " + result.Length.ToString ());
Debug.WriteLine (message + ", current length: " + result.Length.ToString ());
if (headers) {
if (dgv.SelectionMode != DataGridViewSelectionMode.CellSelect)
return;
if (dgv.ClipboardCopyMode != DataGridViewClipboardCopyMode.EnableAlwaysIncludeHeaderText)
return;
}
int tab = 3;
DataObject data;
string csv = null, html = null, utext = null, text = null;
string code = null;
DataGridViewRowHeaderTest.DataGridViewRowHeaderClipboardCell row_header_cell;
DataGridViewColumnHeaderTest.DataGridViewColumnHeaderClipboardCell col_header_cell;
int counter = 0;
append (result, tab, "using (DataGridView dgv = DataGridViewCommon.CreateAndFillForClipboard ()) {");
tab++;
append (result, tab, "dgv.SelectionMode = DataGridViewSelectionMode.{0};", dgv.SelectionMode.ToString ());
append (result, tab, "dgv.ClipboardCopyMode = DataGridViewClipboardCopyMode.{0};", dgv.ClipboardCopyMode.ToString ());
switch (dgv.SelectionMode) {
case DataGridViewSelectionMode.FullRowSelect:
foreach (DataGridViewRow row in dgv.Rows) {
if (row.Selected) {
append (result, tab, "dgv.Rows [{0}].Selected = true;", row.Index);
}
}
break;
case DataGridViewSelectionMode.FullColumnSelect:
foreach (DataGridViewColumn col in dgv.Columns) {
if (col.Selected) {
append (result, tab, "dgv.Columns [{0}].Selected = true;", col.Index);
}
}
break;
case DataGridViewSelectionMode.ColumnHeaderSelect:
case DataGridViewSelectionMode.RowHeaderSelect:
case DataGridViewSelectionMode.CellSelect:
if (dgv.SelectionMode == DataGridViewSelectionMode.RowHeaderSelect) {
foreach (DataGridViewRow row in dgv.Rows) {
if (row.Selected) {
append (result, tab, "dgv.Rows [{0}].Selected = true;", row.Index);
}
}
}
if (dgv.SelectionMode == DataGridViewSelectionMode.ColumnHeaderSelect) {
foreach (DataGridViewColumn col in dgv.Columns) {
if (col.Selected) {
append (result, tab, "dgv.Columns [{0}].Selected = true;", col.Index);
}
}
}
for (int r = 0; r < dgv.RowCount; r++) {
for (int c = 0; c < dgv.ColumnCount; c++) {
bool rowS = dgv.Rows [r].Selected;
bool colS = dgv.Columns [c].Selected;
bool cellS = dgv.Rows [r].Cells [c].Selected;
if ((rowS || colS) && !cellS) {
append (result, tab, "dgv.Rows [{0}].Cells [{1}].Selected = false;", r, c);
} else if ((!rowS && !colS) && cellS) {
append (result, tab, "dgv.Rows [{0}].Cells [{1}].Selected = true;", r, c);
}
}
}
break;
}
if (!headers) {
data = dgv.GetClipboardContent ();
append (result, tab, "data = dgv.GetClipboardContent ();");
if (data == null) {
append (result, tab, "Assert.IsNull (data, {0});", cs_encode ("#" + message + "-" + (counter++).ToString ()));
} else {
append (result, tab, "Assert.IsNotNull (data, {0});", cs_encode ("#" + message + "-" + (counter++).ToString ()));
csv = data.GetData (DataFormats.CommaSeparatedValue) as string;
html = data.GetData (DataFormats.Html) as string;
utext = data.GetData (DataFormats.UnicodeText) as string;
text = data.GetData (DataFormats.Text) as string;
append (result, tab, "Assert.AreEqual ({0}, data.GetData (DataFormats.CommaSeparatedValue), {1});", cs_encode (csv), cs_encode ("#" + message + "-" + (counter++).ToString ()));
append (result, tab, "Assert.AreEqual ({0}, data.GetData (DataFormats.Html), {1});", cs_encode (html, @"""\r\n"""), cs_encode ("#" + message + "-" + (counter++).ToString ()));
append (result, tab, "Assert.AreEqual ({0}, data.GetData (DataFormats.UnicodeText), {1});", cs_encode (utext), cs_encode ("#" + message + "-" + (counter++).ToString ()));
append (result, tab, "Assert.AreEqual ({0}, data.GetData (DataFormats.Text), {1});", cs_encode (text), cs_encode ("#" + message + "-" + (counter++).ToString ()));
}
} else {
bool [] bools = new bool [] { true, false };
string [] formats = new string [] { DataFormats.Text, DataFormats.UnicodeText, DataFormats.Html, DataFormats.CommaSeparatedValue };
foreach (bool a in bools) {
foreach (bool b in bools) {
//.........这里部分代码省略.........
示例5: CopyDataGridView
/// <summary>
/// 通过剪贴板复制DataGridView控件中所选中的内容.
/// </summary>
/// <param DGView="DataGridView">DataGridView类</param>
/// <return>字符串</return>
public string CopyDataGridView(DataGridView DGView)
{
string tem_str = "";
if (DGView.GetCellCount(DataGridViewElementStates.Selected) > 0)
{
try
{
//将数据添加到剪贴板中
Clipboard.SetDataObject(DGView.GetClipboardContent());
//从剪贴板中获取信息
tem_str = Clipboard.GetText();
}
catch (System.Runtime.InteropServices.ExternalException)
{
return "";
}
}
return tem_str;
}
示例6: CopyData
private void CopyData(ref DataGridView dgv)
{
if (dgv.GetCellCount(DataGridViewElementStates.Selected) > 0)
{
try
{
// Add the selection to the clipboard.
Clipboard.SetDataObject(dgv.GetClipboardContent());
}
catch (System.Runtime.InteropServices.ExternalException)
{
MessageBox.Show("The Clipboard could not be accessed. Please try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
示例7: CopyToClipboard
public static void CopyToClipboard(DataGridView v)
{
object o = v.GetClipboardContent();
if (o != null)
{ //Select in cell
Clipboard.SetDataObject(o);
}
else if (v.IsCurrentCellInEditMode && v.CurrentCell.EditType.Name == "DataGridViewTextBoxEditingControl")
{ //Select in text
DataGridViewTextBoxEditingControl tb = v.EditingControl as DataGridViewTextBoxEditingControl;
string s = tb.SelectedText;
if (s.Length > 0)
{
Clipboard.SetText(s);
}
}
}
示例8: CopyToClipboard
private void CopyToClipboard(DataGridView DGV)
{
DataObject dataObj = DGV.GetClipboardContent();
if (dataObj != null)
Clipboard.SetDataObject(dataObj);
}
示例9: DataGridViewEnableCopy
private void DataGridViewEnableCopy(DataGridView dgv)
{
Clipboard.SetData(DataFormats.Text,dgv.GetClipboardContent().GetData(DataFormats.Text.ToString()));
}
示例10: CopyActiveGridCellToClipboard
private void CopyActiveGridCellToClipboard(DataGridView visibleDataGridView)
{
if (visibleDataGridView.GetCellCount(DataGridViewElementStates.Selected) > 0)
{
Clipboard.SetDataObject(visibleDataGridView.GetClipboardContent());
}
}
示例11: CopiarEmDataGrid
private static void CopiarEmDataGrid(DataGridView dtgGrid)
{
if ((dtgGrid.GetCellCount(DataGridViewElementStates.Selected) <= 0)||
(dtgGrid.GetClipboardContent()==null)) return;
try
{
Clipboard.SetDataObject(dtgGrid.GetClipboardContent());
}
catch { return;}
DataGridViewSelectedCellCollection celulas = dtgGrid.SelectedCells;
foreach (DataGridViewCell cel in celulas)
{
cel.Style.SelectionBackColor = System.Drawing.Color.Coral;
}
}