all groups > dotnet windows forms databinding > august 2007 >
You're in the

dotnet windows forms databinding

group:

Binding to a business object - Type name does not exist


Binding to a business object - Type name does not exist NeilL
8/12/2007 5:14:17 PM
dotnet windows forms databinding:
I know that this is really trivial but has been bugging me for some time and
I can't figure out what I'm doing wrong.

I have a Windows form and I'm binding a business object (a class defined
within the current application and current application namespace). When I
define the datasource it creates the following

this.tasterBindingSource.DataSource = typeof(TastingMaster.Taster);

Which does not compile since the compiler can not resolve the class form how
it was specified (namespacename.classname). I get the error

The type name 'Taster' does not exist in the type
'TastingMaster.TastingMaster'
If I hand edit the above to either

this.tasterBindingSource.DataSource = typeof(global::TastingMaster.Taster);
or just
this.tasterBindingSource.DataSource = typeof(Taster);

Things work as expected.

So, can someone tell me how I should be doing this to get the code generated
correctly the first time?

By the way, I used the datasource wizard to create the above.

--
Re: Binding to a business object - Type name does not exist Bob Powell [MVP]
8/13/2007 12:00:00 AM
Why are you using the type of the object as the data source? surely you need
a concrete instance of some class rather than it's type - which is a whole
different thing -

Data source properties are usually Object based so that you can use any one
of the various list, collection or bindinglist style objects so the property
will happily accept a type but no sensible binding will take place.

--
--
Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.


[quoted text, click to view]
Re: Binding to a business object - Type name does not exist Marc Gravell
8/13/2007 12:00:00 AM
To be fair to the OP, that is exactly what the IDE spits out... the
binding code has a special case for Type instances, meaning that it
(broadly) uses the TypeDescriptor.GetProperties(type) overload, rather
than the TypeDescriptor.GetProperties(object) version. This means that
it does, as you would hope, list the properties for the associated
Type, rather than the properties of a Type instance.

Marc

Re: Binding to a business object - Type name does not exist Marc Gravell
8/13/2007 12:00:00 AM
Is this just because you have a form (or other class) or property
whose name is the same (in a different namespace), thus confusing the
compiler?

In which case either the global:: or an alias (using SomeOtherName =
blah.bloop.ClassName) directive should suffice.

Marc

Re: Binding to a business object - Type name does not exist NeilL
8/13/2007 6:56:06 AM
Marc,
Thanks for the reply. I don't have any other classes or forms with the same
name in any namespace. This happens to be a class that is in a source file
with another class and not is a separate .cs file but that should not be the
problem.

Is there someplace in the IDE where I can specify the global:: so that I
don't have to hand edit the designer generated code each time it gets
regenerated?

Thanks
--
Neil


[quoted text, click to view]
Re: Binding to a business object - Type name does not exist NeilL
8/13/2007 7:42:03 AM
Thanks for the advice on not using the IDE after it gets close. I've been
using the Infragistics grid controls and have found that it does decide to
discard all my stuff for no known reason so I was moving to your cut/paste
approach.

I also tried editing the datasource file that had configuration info to see
if I could fix it up there ... no luck with that either.

As for a sample, I don't have anything that I can do easily but let me see
what I can do.

I've had exactly the same problem with components that I have in another
project where, if I drop them on a form the code generated has the same type
issue that I never figured out.

--
Neil


[quoted text, click to view]
Re: Binding to a business object - Type name does not exist Marc Gravell
8/13/2007 3:12:50 PM
Not that I know of.

However - on a related note, allow me to warn you that the IDE
sometimes gets very flakey about class bindings. If it decides it
doesn't like you, it will throw them all away. As such, I tend to only
work in the designer until it is "close enough", then I cut/paste the
code into a private method (and call it at some point in the
Form/Control startup).

Any more tweaks I do directly in the snipped code. You don't get to
see the columns in the designer, but it tends to last longer.

Your mileage may vary ;-p

Marc

Re: Binding to a business object - Type name does not exist Marc Gravell
8/13/2007 3:13:29 PM
Just as an aside - do you have a fragment (just a few classes etc)
that reproduce this?

Marc

AddThis Social Bookmark Button