當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。