Click here to Skip to main content
15,902,492 members
Home / Discussions / C#
   

C#

 
GeneralReflection and array´s... Pin
Norman-Timo2-Aug-04 0:43
Norman-Timo2-Aug-04 0:43 
GeneralRe: Reflection and array´s... Pin
leppie2-Aug-04 1:01
leppie2-Aug-04 1:01 
GeneralRe: Reflection and array´s... Pin
leppie2-Aug-04 1:08
leppie2-Aug-04 1:08 
GeneralRe: Reflection and array´s... Pin
Norman-Timo2-Aug-04 1:30
Norman-Timo2-Aug-04 1:30 
GeneralRe: Reflection and array´s... Pin
leppie2-Aug-04 4:14
leppie2-Aug-04 4:14 
GeneralRe: Reflection and array´s... Pin
Norman-Timo2-Aug-04 20:00
Norman-Timo2-Aug-04 20:00 
QuestionHow to decide Page Break insertion criteria in RTF doc? Pin
sachinkalse2-Aug-04 0:05
sachinkalse2-Aug-04 0:05 
Generalserialize an object for use by drag & drop Pin
misterbear1-Aug-04 23:15
misterbear1-Aug-04 23:15 
Hello, I posted a similar question a couple of days ago, got some advice but don't seem to be able
to make this one work anyway. Here is the problem: I have a custom class derived from treenode that I want to be able to perform drag'n'drop on to another instance of the same application. I want to serialize the treenode so I implement the ISerializable interface and add a constructor taking a SerializationInfo and a StreamingContext parameter

The class essentially looks like this:
<br />
[Serializable()]<br />
public class InheritedTreeNode : TreeNode, ISerializable<br />
{<br />
   bool bool_property1, bool_property2, bool_property3;<br />
   string string_property4;<br />
   public InheritedTreeNode() : base() {}<br />
   ...<br />
}<br />


here's what the serialization code in the InheritedTreeNode does:

<br />
public void GetObjectData(SerializationInfo info, StreamingContext context)<br />
{<br />
  // Serialize all properties of this item<br />
  info.AddValue("bool_property1", typeof(bool));<br />
  info.AddValue("bool_property2", typeof(bool));<br />
  info.AddValue("bool_property3", typeof(bool));<br />
  info.AddValue("string_property4", typeof(string));<br />
<br />
  // serialize all it's children<br />
  ArrayList al = new ArrayList();<br />
  foreach(InheritedTreeNode itn in this.Nodes)<br />
    al.Add(mc2);<br />
  info.AddValue("Nodes", typeof(ArrayList));<br />
}<br />


...and here is how it is Deserialized:

<br />
public InheritedTreeNode(SerializationInfo info, StreamingContext context) : base()<br />
{<br />
  this.bool_property1 = info.GetBoolean("bool_property1");<br />
  this.bool_property2 = info.GetBoolean("bool_property2");<br />
  this.bool_property3 = info.GetBoolean("bool_property3");<br />
  this.string_property4 = info.GetString("string_property4");<br />
<br />
  // copy all child nodes<br />
  ArrayList al = (ArrayList)info.GetValue( "Nodes", typeof(ArrayList) );<br />
  foreach(MyTreeNode2 mc2 in al)<br />
  Nodes.Add(mc2);<br />
}<br />


now for drag'n'drop i do this:

<br />
BinaryFormatter bf = new BinaryFormatter();<br />
MemoryStream ms = new MemoryStream();<br />
bf.serialize(ms, instance_of_a_tree_node);<br />
<br />
DataObject dObj = new DataObject("InheritedTreeNode", ms)<br />
theTreeView.DoDragDrop( dObj, DragDropEffects.All );<br />


and when dropping in the other tree view the code looks like:

<br />
<br />
IFormatter formatter = new BinaryFormatter();<br />
MemoryStream ms = (MemoryStream)e.Data.GetData( "InheritedTreeNode" );<br />
ms.Position = 0;<br />
InheritedTreeNode data = (InheritedTreeNode)formatter.Deserialize(ms);<br />
<br />


this will throw an exception in the deserialization constructor at the first info.getBoolean() call
saying that it is an invalid cast...

Is the problem that i put the memorystream object on the clipboard, because it's a reference? In that case, how do I put copy of the bytes contained in it onto the clipboard in global memory so that other instance can retrieve it?

the byte[] of the memory stream
Questionglobal Variables?? Pin
JayJ1-Aug-04 22:37
JayJ1-Aug-04 22:37 
AnswerRe: global Variables?? Pin
El'Cachubrey1-Aug-04 23:13
El'Cachubrey1-Aug-04 23:13 
AnswerRe: global Variables?? Pin
sreejith ss nair1-Aug-04 23:18
sreejith ss nair1-Aug-04 23:18 
AnswerRe: global Variables?? Pin
ILoveCS1-Aug-04 23:22
ILoveCS1-Aug-04 23:22 
GeneralRe: global Variables?? Pin
Colin Angus Mackay1-Aug-04 23:55
Colin Angus Mackay1-Aug-04 23:55 
GeneralRe: global Variables?? Pin
misterbear2-Aug-04 0:17
misterbear2-Aug-04 0:17 
GeneralRe: global Variables?? Pin
Colin Angus Mackay2-Aug-04 0:34
Colin Angus Mackay2-Aug-04 0:34 
GeneralRESOLVED Pin
JayJ2-Aug-04 5:09
JayJ2-Aug-04 5:09 
GeneralRe: global Variables?? Pin
ILoveCS2-Aug-04 15:36
ILoveCS2-Aug-04 15:36 
GeneralRe: global Variables?? Pin
Colin Angus Mackay2-Aug-04 23:01
Colin Angus Mackay2-Aug-04 23:01 
Questionhow to &quot;refocus&quot; a TextBox Pin
Stephan Wright1-Aug-04 21:25
Stephan Wright1-Aug-04 21:25 
Answersolved(Re: how to "refocus" a TextBox) Pin
Stephan Wright1-Aug-04 21:42
Stephan Wright1-Aug-04 21:42 
GeneralRe: solved(Re: how to &quot;refocus&quot; a TextBox) Pin
exhaulted1-Aug-04 22:40
exhaulted1-Aug-04 22:40 
QuestionWhy there appear exception when save axWebBrowser's content ? Pin
Anonymous1-Aug-04 21:13
Anonymous1-Aug-04 21:13 
AnswerRe: Why there appear exception when save axWebBrowser's content ? Pin
BeiJing20081-Aug-04 21:21
BeiJing20081-Aug-04 21:21 
GeneralRe: Why there appear exception when save axWebBrowser's content ? Pin
Paul Evans1-Aug-04 22:21
Paul Evans1-Aug-04 22:21 
GeneralRe: Why there appear exception when save axWebBrowser's content ? Pin
BeiJing20081-Aug-04 23:42
BeiJing20081-Aug-04 23:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.