can't add item to listbox
-
hi folks, can anyone please tell me why i can't add a string in a listbox? here's the code Form1.cs private void InitializeComponent() { printMsg += new myEventHandler(AddItem); //some code here } public delegate void myEventHandler(string msg); public event myEventHandler printMsg; [STAThread] static void Main() { Application.Run(new Form1()); } public void AddItem(string msg) { listBox1.Items.Add(msg); } --------------------------------------------- Form2.cs private void button1_Click(object sender, System.EventArgs e) { Form1 f = new Form1(); f.AddItem("just testing"); } i'll appreciate any help. thanks
-
hi folks, can anyone please tell me why i can't add a string in a listbox? here's the code Form1.cs private void InitializeComponent() { printMsg += new myEventHandler(AddItem); //some code here } public delegate void myEventHandler(string msg); public event myEventHandler printMsg; [STAThread] static void Main() { Application.Run(new Form1()); } public void AddItem(string msg) { listBox1.Items.Add(msg); } --------------------------------------------- Form2.cs private void button1_Click(object sender, System.EventArgs e) { Form1 f = new Form1(); f.AddItem("just testing"); } i'll appreciate any help. thanks
lagumaster wrote:
Form1 f = new Form1();
You will need to show that form somehow, else you will never see it being added :)**
How xacc.ide transforms text to colored words on the screen
Intel PentuimM (aka Centrino) undervolting**
-
hi folks, can anyone please tell me why i can't add a string in a listbox? here's the code Form1.cs private void InitializeComponent() { printMsg += new myEventHandler(AddItem); //some code here } public delegate void myEventHandler(string msg); public event myEventHandler printMsg; [STAThread] static void Main() { Application.Run(new Form1()); } public void AddItem(string msg) { listBox1.Items.Add(msg); } --------------------------------------------- Form2.cs private void button1_Click(object sender, System.EventArgs e) { Form1 f = new Form1(); f.AddItem("just testing"); } i'll appreciate any help. thanks
Form1.cs
private void InitializeComponent() {
printMsg += new myEventHandler(AddItem);
//some code here
}public delegate void myEventHandler(string msg);
public event myEventHandler printMsg;public void AddItem(string msg) {
listBox1.Items.Add(msg);
}Form2.cs
[STAThread]
Form1 frm;
static void Main() {
frm = new Form1();
Application.Run(frm);
}private void button1_Click(object sender, System.EventArgs e) {
//Form1 f = new Form1();
frm.AddItem("just testing");
}