Note that there are some explanatory texts on larger screens.

plurals
  1. PObind a list variable to text box
    text
    copied!<p>i have a new question. i have a code to load a list from binary file, i think i did it right but i need to make each variable show in its own text box. this is the ting i cannot find out how to do. can anyone help me or point me to where i can find the information?</p> <pre><code>using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; using System.Runtime.Serialization.Formatters.Binary; namespace test { public partial class Form1 : Form { [Serializable] public class ore { public float Titan; public float Eperton; } ore b1 = null; ore b2 = null; public Form1() { InitializeComponent(); b2 = new ore(); b1 = new ore(); } private void textBox1_TextChanged(object sender, EventArgs e) { float tempFloat; if (float.TryParse(textBox1.Text, out tempFloat)) { b1.Titan = tempFloat; } else MessageBox.Show("uh oh"); } private void textBox2_TextChanged(object sender, EventArgs e) { float tempFloat; if (float.TryParse(textBox1.Text, out tempFloat)) { b2.Eperton = tempFloat; } else MessageBox.Show("uh oh"); } private void button1_Click(object sender, EventArgs e) { List&lt;ore&gt; oreData = new List&lt;ore&gt;(); oreData.Add(b1); oreData.Add(b2); FileStream fs = new FileStream("ore.dat", FileMode.Create); BinaryFormatter bf = new BinaryFormatter(); bf.Serialize(fs, oreData); fs.Close(); } private void textBox3_TextChanged(object sender, EventArgs e) { } private void textBox4_TextChanged(object sender, EventArgs e) { } List&lt;ore&gt; books = new List&lt;ore&gt;(); private void button2_Click(object sender, EventArgs e) { FileStream fs = new FileStream("ore.dat", FileMode.Open); BinaryFormatter bf = new BinaryFormatter(); List&lt;ore&gt; books = (List&lt;ore&gt;)bf.Deserialize(fs); fs.Close(); if (books.Count &gt; 1) { textBox3.Text = books[0];//update the first text textBox4.Text = books[1];//update the second text } } } </code></pre> <p>}</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload