Listbox

  • Thread starter Thread starter xzzy
  • Start date Start date
X

xzzy

how would I add items to a listbox from a function in a different class in
the solution?

i.e. something like:
namespace.frmMain.listBox1.items.add(0,"text to add");

Thank you
 
do you mean like this?


public class frmMain : System.Windows.Forms.Form
{

public System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.Button btnConfigure;


if so then I'm sorry but I still cannot reference the listbox outside of
frmMain
 
this does not expose listBox1 as public:

public class frmMain : System.Windows.Forms.Form
{

MyApp myAppl = new MyApp();

public System.Windows.Forms.ListBox listBox1;


what should I be doing?


Thank you
 
Cant you simply pass a reference to your listbox object to the that class
and use it to add items to the list?
 
I am fairly new to c#, thank you for your help with this:

+ + + + + + + + +

public class frmMain : System.Windows.Forms.Form
{
public System.Windows.Forms.ListBox listBox1;

+ + + + + + + + +

ListboxMsgs lb = new ListboxMsgs();

//++ the reference to frmMain.listBox1 does not work: ++//
lb.test(frmMain.listBox1,"My message");

+ + + + + + + + +

using System;
using System.Windows.Forms;

namespace PagingDN
{
public class ListboxMsgs {
public void test(System.Windows.Forms.ListBox listBox1, string xMSG) {
listBox1.Items.Add(xMSG);
if(listBox1.Items.Count>300){
// listBox1.clear();
}
}
}
}


+ + + + + + + + +
 
Back
Top