473,406 Members | 2,710 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,406 software developers and data experts.

How do I get control of a list box outside of the namespace from a class

What I am trying to do is to modify the Listbox

from a class that is in the main namespace.

I have tried
doing a using WindowsApplication2;

WindowsApplication2.Form1 y = new Form1();

y.listbox1.Insert.Add(String)


But the list box does not seem to populate as it would had I done

listbox1.Insert.Add(String)

In the main. What am I doing wrong?
Mar 17 '09 #1
3 1246
tlhintoq
3,525 Expert 2GB
A. Directly affect controls from different threads other than the UI thread that created the control is going to cause problems.

B. I've always added items to ListBoxes by added to its .Items collection:
listbox1.Items.Add(string);
Mar 17 '09 #2
Yes I have done this the problem is I have a class file Crypto that is created and called and within this class is where I try to access the list box and cant seem to do it.
Mar 17 '09 #3
tlhintoq
3,525 Expert 2GB
Is WindowsApplication2 really a completely seperate second application? Do you have one application trying to access the listbox of a totally different application? Or just one class trying to access the listbox of a different class? One form trying to access the listbox of another form?

It really isnt' a good plan to have your class CRYPTO being tightly tied to the UI controls. It makes it a bear to update and make changes later.

Better to have CRYPTO raise an event that your UI is subscribed to. When crypto raises an event with the string as part of its arguments, then the form with the listbox can receive the event and react accordingly.

Think of it this way... The UI has only one purpose: User Interface. Your crypto class has only one purpose: Do cryptography. When crypto is done it should raise it's hand and yell out the answer. The UI can react as it needs to. But crypto doesn't need to understand what UI does, or even how many other classes are listening. You could have 10 classes all listening for crypto to finish and yell the answer. One does the listbox... one sends the answer over a socket connection... one stops a method timer... one logs the action... You wouldn't want to make your crypto class do all those other things explicitly.
Mar 17 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Steven | last post by:
Hi, I'm creating a custom checkbox list control which will take 2 arraylists as input. (One will contain Names and other will contain 0s and 1s. 0 - uncheck 1- check). I'm able to create the...
2
by: paul meaney | last post by:
All, myself and another developer have been staring blankly at a screen for the past 48 hours and are wondering just what stunningly obvious thing we are missing. We are trying to load up 2...
5
by: Paul Bromley | last post by:
Can someone give me a very simple example on how to do this? As an example I have a commaned button in a user control. Once this user control is placed on a form I want to be able to respond in the...
7
by: hummh | last post by:
Hello out there, I´m making my first steps with ASP.NET 2.0 and have he following problem: I´ve implemented a Web User Control that sits in the root of my ASP.NET Website. I want to use the...
0
by: Jeremy Chapman | last post by:
I have included below virtually all the code to a control I'm trying to build. My issue is that an array list property in my control does not get persisted properly to the aspx page code in design...
2
by: rn5a | last post by:
Assume that a user control (MyUC.ascx) encapsulates 2 TextBoxes with the IDs 'txt1' & 'txt2' respectively. To use this user control in an ASPX page, the following Register directive will be...
7
by: Juha Nieminen | last post by:
This is possible: namespace X { class A; } class X::A { <implementation}; However, what about nameless namespaces? Does this do what I want? namespace { class A; }
0
by: ChopStickr | last post by:
I have a custom control that is embedded (using the object tag) in an html document. The control takes a path to a local client ini file. Reads the file. Executes the program specified in...
3
by: raylopez99 | last post by:
This is an example of using multiple comparison criteria for IComparer/ Compare/CompareTo for List<and Array. Adapted from David Hayden's tutorial found on the net, but he used ArrayList so the...
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: 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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.