473,382 Members | 1,362 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,382 software developers and data experts.

How to display the name of an object instance?

Hi,

I have a ToolbarButton and I want to print out the instance name. This
is easy to do with objects that inherit from Control because there is
a .Name property. However, with other objects like ToolbarButton I
don't see how to do this.

Advice? Ideas? THANKS!

ToolbarButton tbbMyButton;

public static void ShowName(object o)
{
if ( o is ToolbarButton )
{
Console.Writeline(tbbMyButton.Name); // Doesn't work, no Name
property
}
}

Maybe something with reflection?

Thanks!!!

John
Nov 16 '05 #1
3 1571
John <jo********@hotmail.com> wrote:
I have a ToolbarButton and I want to print out the instance name. This
is easy to do with objects that inherit from Control because there is
a .Name property. However, with other objects like ToolbarButton I
don't see how to do this.

Advice? Ideas? THANKS!

ToolbarButton tbbMyButton;

public static void ShowName(object o)
{
if ( o is ToolbarButton )
{
Console.Writeline(tbbMyButton.Name); // Doesn't work, no Name
property
}
}

Maybe something with reflection?


Objects don't *have* names usually. What do you actually want to see?

Don't forget that there's a big difference between an object and a
variable containing a reference to an object. A variable has a name,
but there could be lots of variables with references to a specific
object - or none!

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
John,

The Name property of a Control instance isn't really applicable. Say
you had a button, which was named mobjButton. What happens when you do
this?

// Assign the button locally.
Button pobjButton = mobjButton;

What should the name be then? mobjButton or pobjButton? Both are
legitimate names for the object instance.

If you want to get the name of the field for an object instance, then
you can call the GetFields method on the Type class. Since all instances
will have the same field names, you can just use these.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"John" <jo********@hotmail.com> wrote in message
news:d8**************************@posting.google.c om...
Hi,

I have a ToolbarButton and I want to print out the instance name. This
is easy to do with objects that inherit from Control because there is
a .Name property. However, with other objects like ToolbarButton I
don't see how to do this.

Advice? Ideas? THANKS!

ToolbarButton tbbMyButton;

public static void ShowName(object o)
{
if ( o is ToolbarButton )
{
Console.Writeline(tbbMyButton.Name); // Doesn't work, no Name
property
}
}

Maybe something with reflection?

Thanks!!!

John

Nov 16 '05 #3
That helps a lot. Thank you!

I was so focused on the reference to the instance that I forgot to
consider the FieldInfo that I get from the type. FieldInfo has exactly
what I need.

THANKS!!!
John

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:<#r**************@TK2MSFTNGP12.phx.gbl>...
John,

The Name property of a Control instance isn't really applicable. Say
you had a button, which was named mobjButton. What happens when you do
this?

// Assign the button locally.
Button pobjButton = mobjButton;

What should the name be then? mobjButton or pobjButton? Both are
legitimate names for the object instance.

If you want to get the name of the field for an object instance, then
you can call the GetFields method on the Type class. Since all instances
will have the same field names, you can just use these.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"John" <jo********@hotmail.com> wrote in message
news:d8**************************@posting.google.c om...
Hi,

I have a ToolbarButton and I want to print out the instance name. This
is easy to do with objects that inherit from Control because there is
a .Name property. However, with other objects like ToolbarButton I
don't see how to do this.

Advice? Ideas? THANKS!

ToolbarButton tbbMyButton;

public static void ShowName(object o)
{
if ( o is ToolbarButton )
{
Console.Writeline(tbbMyButton.Name); // Doesn't work, no Name
property
}
}

Maybe something with reflection?

Thanks!!!

John

Nov 16 '05 #4

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

Similar topics

1
by: FrankBooth | last post by:
Hello, I have a list of names, and when I click ona name I want the extar info to show and then I want to clcik and hide it again. I have the following HTML which works perfectly if I use one...
6
by: Martin | last post by:
I'd like to be able to get the name of an object instance from within a call to a method of that same object. Is this at all possible? The example below works by passing in the name of the object...
2
by: Mamatha | last post by:
Hi I want to add an icon to the textbox's text. I don't know how to display icon in textbox in VB.NET. If any one knows please let me know. Thanks in advance. Mamatha
3
by: Nofi | last post by:
Hello, I'm trying to fill my combobox per code, not with a DataSet because I want to have an empty row in it and this wasn't possible when working with a DataSet. The fill works fine, but when I...
1
by: rbinington | last post by:
Hi, I am trying to write a DNN module that has the ability to insert articles into an article repository. I want the users to be able to move pages around and enter text into the FCKEditor. I...
6
sammyboy78
by: sammyboy78 | last post by:
I'm trying to display my array of objects in a GUI. How do I get JLabel to refer to the data in my objects? I've read my textbook and some tutorials online I just cannot get this. Plus all the...
0
parshupooja
by: parshupooja | last post by:
Contact Reply 1 point Member propoo Joined on 08-31-2007, 10:32 PM Posts 3 Hey all ,
0
by: AlDave | last post by:
What I'm trying display is after the user chooses the product (1st category) from a dropdown, then the dataview will display; The category any reports under that subcategory any...
1
by: =?Utf-8?B?Q2hhcmxlcw==?= | last post by:
I'm running VS2008 & attempting to solve a problem I've encountered while developing some software for our business. Here's the basic idea...I've created a class that represents a file (with...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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?
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...

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.