Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. can't add item to listbox

can't add item to listbox

Scheduled Pinned Locked Moved C#
testingbeta-testinghelpquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lagumaster
    wrote on last edited by
    #1

    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

    L K 2 Replies Last reply
    0
    • L lagumaster

      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

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      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

      **

      1 Reply Last reply
      0
      • L lagumaster

        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

        K Offline
        K Offline
        KrIstOfK
        wrote on last edited by
        #3

        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");
        }

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups