当前位置: 首页>>代码示例>>C#>>正文


C# DataGridView.GetClipboardContent方法代码示例

本文整理汇总了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);
 }
开发者ID:SyedMdKamruzzaman,项目名称:sap_interface,代码行数:7,代码来源:CDataGridViewUtils.cs

示例2: GetClipboardContentsDisabled

		public void GetClipboardContentsDisabled ()
		{
			using (DataGridView dgv = new DataGridView ()) {
				dgv.ClipboardCopyMode = DataGridViewClipboardCopyMode.Disable;
				object o = dgv.GetClipboardContent ();
			}
		}
开发者ID:ngraziano,项目名称:mono,代码行数:7,代码来源:DataGridViewTest.cs

示例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));
                }
            }
        }
开发者ID:NextStalker,项目名称:BBAuto,代码行数:19,代码来源:MyBuffer.cs

示例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) {
//.........这里部分代码省略.........
开发者ID:vnan122,项目名称:mono,代码行数:101,代码来源:DataGridViewTest.cs

示例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;
 }
开发者ID:TGHGH,项目名称:C-1200,代码行数:24,代码来源:Frm_Main.cs

示例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);
         }
     }
 }
开发者ID:swankham,项目名称:Epicoil,代码行数:15,代码来源:StoreInPlan.cs

示例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);
         }
     }
 }
开发者ID:alcor0,项目名称:ResedUI,代码行数:17,代码来源:Utility.cs

示例8: CopyToClipboard

 private void CopyToClipboard(DataGridView DGV)
 {
     DataObject dataObj = DGV.GetClipboardContent();
     if (dataObj != null)
         Clipboard.SetDataObject(dataObj);
 }
开发者ID:silmarion,项目名称:WPDHelper,代码行数:6,代码来源:Form1_DataGridCCP.cs

示例9: DataGridViewEnableCopy

 private void DataGridViewEnableCopy(DataGridView dgv)
 {
     Clipboard.SetData(DataFormats.Text,dgv.GetClipboardContent().GetData(DataFormats.Text.ToString()));
 }
开发者ID:freudshow,项目名称:raffles-codes,代码行数:4,代码来源:MDIForm.cs

示例10: CopyActiveGridCellToClipboard

 private void CopyActiveGridCellToClipboard(DataGridView visibleDataGridView)
 {
     if (visibleDataGridView.GetCellCount(DataGridViewElementStates.Selected) > 0)
     {
         Clipboard.SetDataObject(visibleDataGridView.GetClipboardContent());
     }
 }
开发者ID:nothrow,项目名称:OrionSDK,代码行数:7,代码来源:QueryTab.cs

示例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;
            }
        }
开发者ID:danieleRocha,项目名称:Momentos,代码行数:17,代码来源:Tabela.cs


注:本文中的System.Windows.Forms.DataGridView.GetClipboardContent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。