Click here to Skip to main content
15,911,039 members
Home / Discussions / C#
   

C#

 
GeneralRe: another problem about Explorer.exe... Pin
nemopeti14-Jun-05 23:10
nemopeti14-Jun-05 23:10 
GeneralRe: another problem about Explorer.exe... Pin
Veelone14-Jun-05 23:18
Veelone14-Jun-05 23:18 
GeneralRe: another problem about Explorer.exe... Pin
nemopeti14-Jun-05 23:26
nemopeti14-Jun-05 23:26 
Generalon windows logon program...help!!! Pin
Veelone14-Jun-05 17:23
Veelone14-Jun-05 17:23 
GeneralRe: on windows logon program...help!!! Pin
nemopeti14-Jun-05 22:59
nemopeti14-Jun-05 22:59 
GeneralRe: on windows logon program...help!!! Pin
Veelone14-Jun-05 23:13
Veelone14-Jun-05 23:13 
GeneralDebugger Failure Pin
Expert Coming14-Jun-05 12:54
Expert Coming14-Jun-05 12:54 
GeneralListBox serialization wont work! :-( Pin
Green Fuze14-Jun-05 12:10
Green Fuze14-Jun-05 12:10 
Hey
I'm really trying to serialize a listbox in my form, but I just keep getting an exception that tells me that it is not serializable

I'm writing down the code of the Main form.

using System;<br />
using System.Drawing;<br />
using System.Collections;<br />
using System.ComponentModel;<br />
using System.Windows.Forms;<br />
using System.Data;<br />
<br />
using System.Runtime.Serialization;<br />
using System.Runtime.Serialization.Formatters.Binary;<br />
<br />
namespace Serialize_ListBox<br />
{<br />
	<br />
	[Serializable()]<br />
	public class MainForm : System.Windows.Forms.Form, ISerializable<br />
	{<br />
		private System.Windows.Forms.ListBox lbText;<br />
		private System.Windows.Forms.Button btnSave;<br />
		private System.Windows.Forms.Button btnAdd;<br />
		private Form ThisForm;<br />
		/// <summary><br />
		/// Required designer variable.<br />
		/// </summary><br />
		private System.ComponentModel.Container components = null;<br />
		<br />
<br />
<br />
		public MainForm()<br />
		{<br />
			//<br />
			// Required for Windows Form Designer support<br />
			//<br />
			InitializeComponent();<br />
<br />
			//<br />
			// TODO: Add any constructor code after InitializeComponent call<br />
			//<br />
<br />
		}<br />
<br />
		/// <summary><br />
		/// Clean up any resources being used.<br />
		/// </summary><br />
		protected override void Dispose( bool disposing )<br />
		{<br />
			if( disposing )<br />
			{<br />
				if (components != null) <br />
				{<br />
					components.Dispose();<br />
				}<br />
			}<br />
			base.Dispose( disposing );<br />
		}<br />
<br />
		#region Windows Form Designer generated code<br />
		/// <summary><br />
		/// Required method for Designer support - do not modify<br />
		/// the contents of this method with the code editor.<br />
		/// </summary><br />
		private void InitializeComponent()<br />
		{<br />
			//initializing stuff....<br />
		}<br />
		#endregion<br />
<br />
		/// <summary><br />
		/// The main entry point for the application.<br />
		/// </summary><br />
		[STAThread]<br />
		static void Main() <br />
		{<br />
			Application.Run(new MainForm());<br />
		}<br />
<br />
		private void btnAdd_Click(object sender, System.EventArgs e)<br />
		{<br />
			AddDialog dlgAddText = new AddDialog();<br />
			<br />
			if(dlgAddText.ShowDialog() == DialogResult.OK)<br />
			{<br />
				lbText.BeginUpdate();<br />
				lbText.Items.Add(dlgAddText.txtAdd.Text);<br />
				lbText.EndUpdate();<br />
			}<br />
		}<br />
<br />
		private void btnSave_Click(object sender, System.EventArgs e)<br />
		{<br />
			System.IO.Stream stream = System.IO.File.Open("listbox.bla", System.IO.FileMode.OpenOrCreate);<br />
			BinaryFormatter BF = new BinaryFormatter();<br />
<br />
			BF.Serialize(stream, lbText);<br />
			stream.Close();<br />
			MessageBox.Show("ListBox Saved");<br />
		}<br />
		<br />
<br />
		//Deserialization constructor<br />
		public MainForm(SerializationInfo info, StreamingContext ctxt)<br />
		{<br />
			lbText = (ListBox)info.GetValue("List", typeof(ListBox));<br />
		}<br />
<br />
		//serialization function<br />
		public void GetObjectData(SerializationInfo info, StreamingContext ctxt)<br />
		{<br />
			info.AddValue("List", lbText);<br />
		}<br />
<br />
<br />
	}<br />
		<br />
}<br />
<br />


till now I serialized strings with no problems, and I don't know why its not working now.

help anyone???

Thanks ALot!
GeneralRe: ListBox serialization wont work! :-( Pin
occcy14-Jun-05 19:57
occcy14-Jun-05 19:57 
GeneralRe: ListBox serialization wont work! :-( Pin
Green Fuze14-Jun-05 20:40
Green Fuze14-Jun-05 20:40 
GeneralRe: ListBox serialization wont work! :-( Pin
occcy14-Jun-05 20:54
occcy14-Jun-05 20:54 
GeneralRe: ListBox serialization wont work! :-( Pin
Green Fuze16-Jun-05 2:23
Green Fuze16-Jun-05 2:23 
GeneralRe: ListBox serialization wont work! :-( Pin
Green Fuze16-Jun-05 4:53
Green Fuze16-Jun-05 4:53 
GeneralRe: ListBox serialization wont work! :-( Pin
occcy16-Jun-05 19:49
occcy16-Jun-05 19:49 
GeneralRe: ListBox serialization wont work! :-( Pin
Green Fuze16-Jun-05 21:55
Green Fuze16-Jun-05 21:55 
GeneralRe: ListBox serialization wont work! :-( Pin
occcy16-Jun-05 22:08
occcy16-Jun-05 22:08 
GeneralTextBox Enter/Break Pin
Expert Coming14-Jun-05 11:16
Expert Coming14-Jun-05 11:16 
GeneralRe: TextBox Enter/Break Pin
bneacetp14-Jun-05 11:31
bneacetp14-Jun-05 11:31 
GeneralRe: TextBox Enter/Break Pin
Vasudevan Deepak Kumar14-Jun-05 19:17
Vasudevan Deepak Kumar14-Jun-05 19:17 
GeneralRe: TextBox Enter/Break Pin
S. Senthil Kumar14-Jun-05 20:08
S. Senthil Kumar14-Jun-05 20:08 
GeneralCommon Languge Runtime Debugging Services Pin
adonisv14-Jun-05 10:19
adonisv14-Jun-05 10:19 
GeneralRe: Common Languge Runtime Debugging Services Pin
nemopeti14-Jun-05 23:34
nemopeti14-Jun-05 23:34 
GeneralRe: Common Languge Runtime Debugging Services Pin
adonisv15-Jun-05 9:16
adonisv15-Jun-05 9:16 
Generalsystem.transactions problem Pin
Anonymous14-Jun-05 10:11
Anonymous14-Jun-05 10:11 
Generalhey Pin
Anonymous14-Jun-05 10:17
Anonymous14-Jun-05 10:17 

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.