473,480 Members | 3,017 Online
Bytes | Software Development & Data Engineering Community
Create 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 1189
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***@vkarlsen.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
9642
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:...
3
4113
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...
18
28707
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,...
3
2337
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...
0
7055
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
6920
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
7106
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...
1
6760
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...
0
7022
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
4501
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3004
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
572
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
206
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...

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.