| View previous topic :: View next topic |
| Author |
Message |
gogodr I post too much
Reputation: 125
Joined: 19 Dec 2006 Posts: 2041
|
Posted: Tue Sep 22, 2009 10:45 pm Post subject: C# Multiple forms not interacting with each other :/ |
|
|
k I have this 2 forms
reminderform.cs and List.cs
I have this button in the reminderform.cs
| Code: | private void Add_Click(object sender, EventArgs e){
List form2 = new List();
form2.ShowDialog();
string remindme = this.Reminder.Text;
form2.listBoxList.Items.Add(remindme) ;
this.Reminder.Text = "";
}
|
which does everything but add the new entry to the list in the other form
whats wrong ? X_x?
___________
forget it, I just discovered it was all about changing the button protection from private to public
|
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Tue Sep 22, 2009 11:26 pm Post subject: |
|
|
| This is a terrible way to architect your program, perhaps you should consider designing your class structure.
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Tue Sep 22, 2009 11:38 pm Post subject: |
|
|
| Events are the best way to handle this if I remember right
|
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Tue Sep 22, 2009 11:41 pm Post subject: |
|
|
| Here is a hint: GUIs are for displaying information, not storing information.
|
|
| Back to top |
|
 |
Odecey Master Cheater
Reputation: 1
Joined: 19 Apr 2007 Posts: 259 Location: Scandinavia
|
Posted: Wed Sep 23, 2009 12:06 am Post subject: |
|
|
This is how I do it:
| Code: |
public partial class List : Form
{
public void UpdateList (List<string> items)
{
foreach(string item in items)
listBoxList.Add(item);
}
}
public partial class form1 : Form
{
List form2 = new List();
List listToShow = new List<string>();
private void Add_Click(object sender, EventArgs e){
if(form2.IsDisposed)
form2.Show();
listToShow.Add(this.reminder.Text);
form2.UpdateList(listToShow);
this.Reminder.Text = "";
}
}
|
Edit:Fixed an error in the code.
_________________
Never confuse activity with productivity. You can be busy without a purpose, but what's the point?- Rick Warren |
|
| Back to top |
|
 |
gogodr I post too much
Reputation: 125
Joined: 19 Dec 2006 Posts: 2041
|
Posted: Wed Sep 23, 2009 8:03 am Post subject: |
|
|
thanks guys but I got it to work yesterday xP I wrote to forget about this post but meh, thanks anyways
this is my current code:
| Code: | namespace WindowsFormsApplication1
{
public partial class ReminderForm : Form
{
public ReminderForm()
{
InitializeComponent();
}
List form2 = new List();
private void Add_Click(object sender, EventArgs e){
form2.listBoxList.Items.Add(this.Date.Value.Day + "/" + this.Date.Value.Month + " at " + this.Time.Text +" "+ this.Reminder.Text);
this.Reminder.Text = "";
}
private void Showlist_Click(object sender, EventArgs e)
{
form2.ShowDialog();
}
}
} |
|
|
| Back to top |
|
 |
|