473,608 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

assuming that object from arraylist is button ??

hi,
Expand|Select|Wrap|Line Numbers
  1. System.Collections.ArrayList a = new ArrayList();
  2. Button b = new Button();
  3. b.Top= 40;
  4. b.Left= 30;
  5. b.Parent= this;
  6. b.Text ="blah blah blah";
  7. a.Add(b);
  8. b.Text= (Button)a[0].text;
  9.  
\c\Form1.cs(124 ): 'object' does not contain a definition for 'text'

how to tell the compiler that this is button ... and get the value from
it...
help please ...
Nov 16 '05 #1
5 1198
May be a little typo, but would give the error you list...

On your last line, the text property needs to have an upper case T

i.e.:

b.Text = (Button)a[0].Text;
Regards,

Peter Chadwick (MCP)
pe**@code-explorers.com

Nov 16 '05 #2
Peter Chadwick (MCP) wrote:
May be a little typo, but would give the error you list...

On your last line, the text property needs to have an upper case T

i.e.:

b.Text = (Button)a[0].Text;
Regards,

Peter Chadwick (MCP)
pe**@code-explorers.com

there was a typo but it didn't solve the problem ... now it is Text...
and the error still exists...
Nov 16 '05 #3
In that case, some extra brackets should solve your problem. You want
the Text property AFTER you have cast the object to a button. And after
all, brackets are free :-)

b.Text= ((Button)a[0]).Text;
Regards,

Peter Chadwick (MCP)
pe**@code-explorers.com

Nov 16 '05 #4
Grisha0 wrote:
Peter Chadwick (MCP) wrote:
May be a little typo, but would give the error you list...

On your last line, the text property needs to have an upper case T

i.e.:

b.Text = (Button)a[0].Text;
Regards,

Peter Chadwick (MCP)
pe**@code-explorers.com

there was a typo but it didn't solve the problem ... now it is Text...
and the error still exists...

found it :D

was : b.Text = (Button)a[0].Text;
should be: b.Text = ((Button)a[0]).Text;
Nov 16 '05 #5
Grisha0 wrote:
Peter Chadwick (MCP) wrote:
May be a little typo, but would give the error you list...

On your last line, the text property needs to have an upper case T

i.e.:

b.Text = (Button)a[0].Text;
Regards,

Peter Chadwick (MCP)
pe**@code-explorers.com

there was a typo but it didn't solve the problem ... now it is Text...
and the error still exists...


(Button)a[0].Text is the same as: (Button)(a[0].Text)
ie. it typecasts the Text property of Object, if that existed, but it
doesn't, hence the error.

--
Lasse Vågsæther Karlsen
http://www.vkarlsen.no/
mailto:la***@vk arlsen.no
PGP KeyID: 0x0270466B
Nov 16 '05 #6

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

Similar topics

17
9678
by: Rodusa | last post by:
I am getting this exception error which is driving me nuts. System.NullReferenceException - Object reference not set to an instance of an object If I comment this line, I don't get any errors: string Total_Dollar_Amount = GetTotal(sql,"test"); namespace SalesReport
3
4139
by: Patrick.O.Ige | last post by:
I'm loading an Array below but getting the error "Object reference not set to an instance saying 'ItemNumber = CType(Args.Item.FindControl("ItemNumber"), TextBox).Text' is the error line. I DON'T KNOW WHAT I'M DOING WRONG I USED ASP.NETWebMatrix and its working well!! Any help!! I have declared ItemNumber as u can see below " :-
18
28733
by: Microsoft | last post by:
When I try this in my code I alwas get an errormessage: "Object reference not set to an instance of an object" Dim g As System.Drawing.Graphics g.DrawString("Test", New Font("Arial", 12, FontStyle.Bold), Brushes.Black, 0, 0) Why is this? Marc
3
2344
by: Michael Slattery | last post by:
Hello, I see quite a few questions, but no valid responses to the question... How do I store an ArrayList of items in a Properties file via the GUI? I am able to select the System.Collections.ArrayList type, but I'm unable to determine what to type into the Value feild for a default setting so the property will not be null at runtime...
0
8063
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8003
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8498
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8152
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8341
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6014
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
3962
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4025
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1331
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.