This property is not relevant for this class. Why?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to databind checklistBox to the binding source on my form. DataSource
and DisplayMember and ValueMember are not available in the designer property
window, and the dont show up in Intellisense.

According to msdn documentation:

This property supports the .NET Framework infrastructure and is not intended
to be used directly from your code.

Gets or sets the data source for the control. This property is not relevant
for this class.

http://msdn2.microsoft.com/en-us/library/system.windows.forms.checkedlistbox.datasource.aspx

However the code below compilies and works:


checkedListBox1.DisplayMember = "name";
checkedListBox1.ValueMember = "id";

Why?
 
I haven't checked, but many times the properties you see in the Designer
aren't *all* the properties a class has, nor are all the methods you see
*all* the methods a class has.

Many times, these extra properties and methods are hidded (they can be
unhidden in Tools...Options of VS .NET) for a reason.

For example, the "object" class has a method called "ToString" (which you
are probably familiar with). Since all objects ultimately derive from the
"object" class, then inheritance would state that all classes have this
method (and indeed, they do), but VS .NET hides this method for many types
in the Framework. Why? Consider this:

It makes perfect sense that occassionally you might want to get the string
representation of a number, so most numeric types will have a ToString
method, as its use is very straight-forward.

But, what about a DataAdapter? What would/should/could you get with
DataAdapter.ToString? It's not so obvious now. But, if you typed this in,
it would compile:

Dim da As New System.Data.DataAdapter(someConnection, someSelectText)
da.ToString()

You wouldn't see ToString come up in the intelliSense, but it would accept
it because a DataAdapter does have this method, it is just hidden on this
type.

So, now you might ask "Why would MS give every type this method if it makes
no sense to use it on every type?". Well, MS makes this method
overrideable, because maybe, to you, calling ToString on a DataAdapter
should return its SelectCommand's CommandText (which is a string). You
could make a new class that inherits from the DataAdapter class and override
the ToString method to return just what you feel you need.

In short (too late!), the method is there because using it is either very
obvious as to what it does or the developer could use it for their own
purpose on nearly everthing they work with.

HTH
 
I haven't checked, but many times the properties you see in the Designer
aren't *all* the properties a class has, nor are all the methods you see
*all* the methods a class has.

Many times, these extra properties and methods are hidded (they can be
unhidden in Tools...Options of VS .NET) for a reason.

Properties can be set to [Browsable(false)] to hide them from the property window in the designer.
For example, the "object" class has a method called "ToString" (which you
are probably familiar with). Since all objects ultimately derive from the
"object" class, then inheritance would state that all classes have this
method (and indeed, they do), but VS .NET hides this method for many types
in the Framework. Why? Consider this:

It makes perfect sense that occassionally you might want to get the string
representation of a number, so most numeric types will have a ToString
method, as its use is very straight-forward.

But, what about a DataAdapter? What would/should/could you get with
DataAdapter.ToString? It's not so obvious now. But, if you typed this in,
it would compile:

Dim da As New System.Data.DataAdapter(someConnection, someSelectText)
da.ToString()

You wouldn't see ToString come up in the intelliSense, but it would accept
it because a DataAdapter does have this method, it is just hidden on this
type.

Well, the Object methods ToString(), Equals(), GetHashCode() and GetType always show up no matter what object you use, but the functionality may change based on what type you call these methods on. The default implementation of ToString will return the type as a string. Overriding ToString to return something else (like the string representation of the number instead of the type System.Int32) is handy and makes good sense for objects that should be listed in a ComboBox etc

It's been a while since I've done VB.Net but I don't think VB.Net hides the basic methods either. Furthermore, there is no DataAdapter class in the framework, and the System.Data.SqlClient.SqlDataAdapter (.net 2.0) has a ToString method visible in both C# and VB.Net

<snip>
 
Well, the Object methods ToString(), Equals(), GetHashCode() and GetType
always show up no matter what object you use

Not true. ToString does not show up on all classes, because not all classes
have a use for it. For one, it doesn't show up on object types!
, but the functionality may change based on what type you call these
methods on. The default implementation of ToString will return the type as
a string. Overriding ToString to return something else (like the string
representation of the number instead of the type System.Int32) is handy and
makes good sense for objects that should be listed in a ComboBox etc

It's been a while since I've done VB.Net but I don't think VB.Net hides
the basic methods either.

See above, yes it does.
Furthermore, there is no DataAdapter class in the framework,

I mis-coded my example code before when I wrote System.Data.DataAdapter, but
there most certainly is a DataAdapter, you are just getting bogged down in
the specific ADO.NET types of DataAdapters.

and the System.Data.SqlClient.SqlDataAdapter (.net 2.0) has a ToString
method visible in both C# and VB.Net

That is true, I should have picked a better example.
 
Well, the Object methods ToString(), Equals(), GetHashCode() and GetType
always show up no matter what object you use

Take a look at most of the Web Form controls in 1.1, they will NOT show a
ToString() method in the intelliSense. Neither will the most fundamental
type: "object" and many many more.
 
Thank you for your replies.
I understand why they would hide some members in Intellisnese. It doesn't
answer my question though.
Why databinding properties for CheckListBox are "hidden". Why does MSDN
documentation say that this method is irrelevant and should not be used in
the code. When databinding does work correctly for this control. To me it's
very relevant properties. Does MS have some good reason for hidding
CheckListBox's databinding related properties?

Thanks.
 
Well, I think it does go to your question. There are other ways of
databinding controls, specifically using databinder.eval.

In ASP.NET for example, datagrids have a datasource and databind method but
the most simple of controls, a Textbox, doesn't. It doesn't mean you can't
databind a textbox, though. You just do it differently.
 
Take a look at most of the Web Form controls in 1.1, they will NOT show a
ToString() method in the intelliSense. Neither will the most fundamental
type: "object" and many many more.

I'm not sure what you are talking about. Both webcontrols and System.Object will display ToString(), Equals(), etc in the IntelliSense. Just because a class doesn't use these methods is no reason for hiding them from the user. If you don't see these methods, have you set some option that will hide inherited methods? What kind of Visual Studio are you using?

Unless, you are talking about static methods.

Entering . after first entering System.Windows.Forms.TextBox will not display ToString() in IntelliSense because it will only show static methods. System.Windows.Forms.TextBox.ToString() will not compile as you can't use an instance method on a class definition. Equals on the other hand is a static method, and will show up on both on the class and on the object.

Any instance of any class will display ToString, Equals, GetHashCode and GetType.
 
No, I'm sorry, you are incorrect (VS .NET 2003, VB).

If you just make instances in ASP .NET of controls, as usual, and then go
into the code-behind and type in one of the instance names and a dot (.),
you will NOT see ToString() for most of the web form controls. I AM
referring to instances of these classes (and therefore, instance methods),
not the classes themselves (shared/static methods)

The Tools...Options setting to "Hide Advanced Members" is set to ON, by
default in VS .NET 2003. To see these members show up in intelliSense for
instances, you must manually turn it off. I would suggest that you have
actually turned that setting off (changed the default) or that this default
is different in VS .NET 2003 vs. 2005.
 
No, I'm sorry, you are incorrect (VS .NET 2003, VB).

If you just make instances in ASP .NET of controls, as usual, and then go
into the code-behind and type in one of the instance names and a dot (.),
you will NOT see ToString() for most of the web form controls. I AM
referring to instances of these classes (and therefore, instance methods),
not the classes themselves (shared/static methods)

The Tools...Options setting to "Hide Advanced Members" is set to ON, by
default in VS .NET 2003. To see these members show up in intelliSense for
instances, you must manually turn it off. I would suggest that you have
actually turned that setting off (changed the default) or that this default
is different in VS .NET 2003 vs. 2005.

C# has this turned off by default, and its been that way since .Net
1.0 AFAIK.
 
No, I'm sorry, you are incorrect (VS .NET 2003, VB).

<snip>

I stand corrected. Indeed, in VS 2003 a VB ASP.NET project will not display ToString in IntelliSense. However, there seems to have been some changes in VS 2005 and VS Orcas regarding this. In VS 2005 a VB ASP.NET application will display IntelliSense in two tabs. A "Common" tab hiding many methods and properties, and "All" displaying everything, including ToString(). The default in VS 2005 is to display "All", however, in VS Orcas the default seem to be to display "Common".

C# on the other hand does not hide anything in any version of Visual Studio, so this appears to be one of the differences in IntelliSense preferences between the C# and VB.Net camps.
 
FYI - For VB .NET, it doesn't matter if it is an ASP .NET project or any
other project type for this behaviour.
 
Back
Top