C
C#•14mo ago
LurkingPsycho

my windows form keeps crashing

I have created a TODO list through out windows form. (still learning) and every time i add a todo it seems to crash all the time. I have treid online bunch of time but cant seemt o find answer
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TODO_LIST
{
public partial class Form2 : Form
{

public Form2()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
string textBox = textBox1.Text.ToString();

if(Form1.instance.listBox.Items.Contains(textBox))
{
MessageBox.Show("Cannot contain same description!", "ERROR");
}
else
{
Form1.instance.listBox.Items.Add(textBox);
}

}


private void textBox1_TextChanged(object sender, EventArgs e)
{

string description;
do
{
description = textBox1.Text;
}
while (!isDescriptionValid(description));
Form1.todo.Add(description);

}

bool isDescriptionValid(string description)
{
if (description == "") return false;
if (Form1.todo.Contains(description)) return false;
return true;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TODO_LIST
{
public partial class Form2 : Form
{

public Form2()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
string textBox = textBox1.Text.ToString();

if(Form1.instance.listBox.Items.Contains(textBox))
{
MessageBox.Show("Cannot contain same description!", "ERROR");
}
else
{
Form1.instance.listBox.Items.Add(textBox);
}

}


private void textBox1_TextChanged(object sender, EventArgs e)
{

string description;
do
{
description = textBox1.Text;
}
while (!isDescriptionValid(description));
Form1.todo.Add(description);

}

bool isDescriptionValid(string description)
{
if (description == "") return false;
if (Form1.todo.Contains(description)) return false;
return true;
}
}
}
No description
15 Replies
LurkingPsycho
LurkingPsychoOP•14mo ago
what form looks like :/
SG97
SG97•14mo ago
that's not a crash
if(Form1.instance.listBox.Items.Contains(textBox))
{
MessageBox.Show("Cannot contain same description!", "ERROR");
}
if(Form1.instance.listBox.Items.Contains(textBox))
{
MessageBox.Show("Cannot contain same description!", "ERROR");
}
which is exactly what it's supposed to do, as you have test already added
LurkingPsycho
LurkingPsychoOP•14mo ago
i think its just visual studio... doesnt seem to crash when runned in exe file ;/ sorry if wasted time but i do have 1 question. is there a way to save progress. like when i reopen the windows from all todos are gone also nothing to do with that message box
SG97
SG97•14mo ago
definitely is possible to save the TODO items json/database
LurkingPsycho
LurkingPsychoOP•14mo ago
oh.. im bad at those ;/
SG97
SG97•14mo ago
might want to start with saving a json file on disk
LurkingPsycho
LurkingPsychoOP•14mo ago
oh ok
SG97
SG97•14mo ago
containing the current todo's then on launch, load up the json and create the todo's it contains
LurkingPsycho
LurkingPsychoOP•14mo ago
that ganna be fun 😄 thanks
SG97
SG97•14mo ago
we all bad at stuff in the beginning
LurkingPsycho
LurkingPsychoOP•14mo ago
il figure way out 🙂 might watch this indian guy tell me how
SG97
SG97•14mo ago
whichever works for you
LurkingPsycho
LurkingPsychoOP•14mo ago
do i close this... or this up permanent
SG97
SG97•14mo ago
might want to close this, and create a new thread when you have problems with the json
LurkingPsycho
LurkingPsychoOP•14mo ago
ok
Want results from more Discord servers?
Add your server