public static void SetDataCSVFromTable(System.Windows.Forms.IDataObject dataobject, System.Data.DataTable datatable) { var default_encoding = System.Text.Encoding.Default; var out_memstream = new System.IO.MemoryStream(); var streamwriter = new System.IO.StreamWriter(out_memstream, default_encoding); var csvwriter = new CSV.CSVWriter(streamwriter); ExportToCSV(datatable, csvwriter); var bytes = out_memstream.ToArray(); var in_memstream = new System.IO.MemoryStream(bytes); dataobject.SetData(System.Windows.Forms.DataFormats.CommaSeparatedValue, in_memstream); }
//Note: GetdataPresent is not reliable for IDataObject that did not originate //from .Net. This rtn is called if it did, but we still don't use GetdataPresent. private void ProcessNetDataObject(System.Windows.Forms.IDataObject NetObject) { if (! (NetObject.GetData(typeof(ArrayList)) == null)) { Type AllowedType = typeof(CShItem); object oCSI; foreach (object tempLoopVar_oCSI in NetObject.GetData(typeof(ArrayList)) as IEnumerable) { oCSI = tempLoopVar_oCSI; if (! AllowedType.Equals(oCSI.GetType())) { m_Draglist = new ArrayList(); goto endOfForLoop; } else { m_Draglist.Add(oCSI); } } endOfForLoop: 1.GetHashCode() ; //nop } //Shell IDList Array is preferred to HDROP, see if we have one if (! (NetObject.GetData("Shell IDList Array") == null)) { //Get it and also mark that we had one m_StreamCIDA = NetObject.GetData("Shell IDList Array") as MemoryStream; //has one, ASSUME that it matchs what we may have gotten from // ArrayList, if we had one of those if (m_Draglist.Count < 1) //if we didn't have an ArrayList, have to build m_DragList { if (! MakeDragListFromCIDA()) //Could not make it { return; //leaving m_IsValid as false } } } //FileDrop is only used to build m_DragList if not already done if (m_Draglist.Count < 1) { if (! (NetObject.GetData("FileDrop") == null)) { string S; foreach (string tempLoopVar_S in NetObject.GetData("FileDrop", true) as IEnumerable) { S = tempLoopVar_S; try //if GetCShitem returns Nothing(it's failure marker) then catch it { m_Draglist.Add(ExpTreeLib.CShItem.GetCShItem(S)); } catch (Exception ex) //Some problem, throw the whole thing away { Debug.WriteLine("CMyDataObject -- Error in creating CShItem for " + S + "\r\n" + "Error is: " + ex.ToString()); m_Draglist = new ArrayList(); } } } } //At this point we must have a valid m_DragList if (m_Draglist.Count < 1) { return; //no list, not valid } //ensure that DataObject has a Shell IDList Array if (m_StreamCIDA == null) //wouldn't be Nothing if it had one { m_StreamCIDA = MakeShellIDArray(m_Draglist); NetObject.SetData("Shell IDList Array", true, m_StreamCIDA); } //At this point, we have a valid DragList and have ensured that the DataObject // has a CIDA. m_IsValid = true; return; }