Note that there are some explanatory texts on larger screens.

plurals
  1. POlistbox adds items somehow
    text
    copied!<p>I have this school project to create a "movie library". It worked great to add "movies" to the library and see the info I typed in.</p> <p>When I debug it I get to type in info about the move and then press add ("Lägg till" button) to save it in a list array. It works fine and everything but except for one problem...the second time I add a movie to the library..it double the info or something :/</p> <p>Code:</p> <pre><code> string title = ""; string genre = ""; string fakta = ""; string lengd = ""; string bluray = "Bluray"; string dvd = ""; string bildlänk = ""; string box1; public void button1_Click(object sender, EventArgs e) { if (radioButton1.Checked || radioButton2.Checked) { title = textBox1.Text; genre = textBox4.Text; lengd = textBox3.Text; fakta = richTextBox1.Text; bildlänk = textBox5.Text; dvd = radioButton2.Text; bluray = radioButton1.Text; if (radioButton1.Checked) { array.Add(a = new Arbetare(title, genre, lengd, fakta, bluray, dvd, bildlänk)); listBox1.Items.Add(title); } else { array.Add(a = new Arbetare(title, genre, lengd, fakta, bluray, dvd, bildlänk)); listBox1.Items.Add(title); } } else { MessageBox.Show("Du kanske ska skriva in något?"); } } public void listBox1_SelectedIndexChanged(object sender, EventArgs e) { if (radioButton1.Checked) { int index = listBox1.SelectedIndex; title = array[index].Title; genre = array[index].Genre; lengd = array[index].Lengd; fakta = array[index].Fakta; bluray = array[index].Bluray; box1 = " Title: " + title + "\n Genre: " + genre + "\n Längd: " + lengd + "\n Fakta: " + fakta + "\n " + bluray; richTextBox1.Text = box1; string text = openFileDialog1bild.FileName; textBox5.Text = text; pictureBox1.ImageLocation = array[index].Bildlänk; } else { int index = listBox1.SelectedIndex; title = array[index].Title; genre = array[index].Genre; lengd = array[index].Lengd; fakta = array[index].Fakta; dvd = array[index].Dvd; box1 = " Title: " + title + "\n Genre: " + genre + "\n Längd: " + lengd + "\n Fakta: " + fakta + "\n " + dvd; richTextBox1.Text = box1; string text = openFileDialog1bild.FileName; textBox5.Text = text; pictureBox1.ImageLocation = array[index].Bildlänk; } } </code></pre> <p>Arbetare class:</p> <pre><code> public class Arbetare : Person { public Arbetare(string title, string genre, string fakta, string lengd, string bluray, string dvd, string bildlänk) :base (genre, fakta, lengd, title, bluray, dvd, bildlänk) { } } </code></pre> <p>Person class:</p> <pre><code>public class Person { protected string title; protected string genre; protected string lengd; protected string fakta; protected string bluray; protected string dvd; protected string bildlänk; public string Title { get { return title; } set { title = value; } } public string Bildlänk { get { return bildlänk; } set { bildlänk = value; } } public string Genre { get { return genre; } set { genre = value; } } public string Lengd { get { return lengd; } set { lengd = value; } } public string Fakta { get { return fakta; } set { fakta = value; } } public string Bluray { get { return bluray; } set { bluray = value; } } public string Dvd { get { return dvd; } set { dvd = value; } } public Person(string title, string genre, string lengd, string fakta, string bluray, string dvd, string bildlänk) { this.Title = title; this.Genre = genre; this.Lengd = lengd; this.Fakta = fakta; this.Bluray = bluray; this.Dvd = dvd; this.bildlänk = bildlänk; } public Person() { this.Title = ""; this.Genre = ""; this.Lengd = ""; this.Fakta = ""; this.Bluray = "Blu-ray"; this.Dvd = "DVD"; this.bildlänk = ""; } } </code></pre> <p>Picture of when I add one movie: <a href="https://imageshack.us/scaled/large/12/98427392.jpg" rel="nofollow">https://imageshack.us/scaled/large/12/98427392.jpg</a></p> <p>Picture when I add the second movie: <a href="https://imageshack.us/scaled/large/443/28077346.jpg" rel="nofollow">https://imageshack.us/scaled/large/443/28077346.jpg</a></p> <p>I'm really sorry if it's hard to read some of it..some of the things are in swedish.</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