473,387 Members | 1,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Listbox

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
Nov 16 '05 #1
5 1804
You need to expose the ListBox as a public property from your Form class.

--
Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph
"xzzy" <mr********@comcast.net> wrote in message
news:_AaTc.302186$XM6.87289@attbi_s53...
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

Nov 16 '05 #2
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
Nov 16 '05 #3
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
Nov 16 '05 #4
Cant you simply pass a reference to your listbox object to the that class
and use it to add items to the list?
"xzzy" <mr********@comcast.net> wrote in message
news:_AaTc.302186$XM6.87289@attbi_s53...
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

Nov 16 '05 #5

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();
}
}
}
}
+ + + + + + + + +

"Ankur" <an***************@hotmail.com> wrote in message
news:ec**************@TK2MSFTNGP10.phx.gbl...
Cant you simply pass a reference to your listbox object to the that class
and use it to add items to the list?
"xzzy" <mr********@comcast.net> wrote in message
news:_AaTc.302186$XM6.87289@attbi_s53...
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


Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: amber | last post by:
Hello. Can someone tell me what I may be doing wrong here? I'm using the code (lboxRP is a listbox): Dim newRPindex As Integer newRPindex = Me.lboxRP.FindString(RP)...
3
by: Paul T. Rong | last post by:
I have a listbox (of product names) control on my form. I want to pass the selected item (a product name) to a subform, and the product unitprice should apear automatically next to the product name...
8
by: Oddball | last post by:
Ok - I have a ListBox control and I'm ready to write my own DrawItem event handler. What I want to draw as the item is another control. I have created a user control that I would like to list in...
2
by: collie | last post by:
Hi, I have 2 listboxes. The first gets populated from the db as soon as the page loads. The second listbox get populated based on the user's selection from the first listbox. However,...
6
by: Chris Leuty | last post by:
I am populating a multiselect Listbox from a dataset, with the content of the listbox filled by one table, and the selections determined from another table. So far, I have been keeping the dataset...
1
by: yamne | last post by:
I have a problem. When I click in edit datagrid button I show two listbox and two button. I use two button to move data between two listbox. My problem is that I can't call the listbox in the...
7
by: Dave | last post by:
Hi all, After unsuccessfully trying to make my own dual listbox control out of arraylists, I decided to look for a 3rd party control. I've looked for over a week now and can't find anything but...
3
by: Ali Chambers | last post by:
Hi, I have created a listbox called "dtlist1" on my VB.NET form. I call a procedure as follows: Private Sub openfile(flname As String) dtlist1.Items.Clear() etc..
1
by: Sunray | last post by:
I have a form called the sales form and i have 2 sets of listboxes So what happens is. i add items form the bottom set of list boxes which are bound to a data base to the top set of list boxes which...
5
by: Academia | last post by:
(If you've seen this in the drawing NG, sorry. I inadvertently sent it there.) I have a listbox populated with Objects. The Class has a String field that ToString returns. I assume that...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.