HighTechTalks DotNet Forums  

BindingSource bound type.

Dotnet Framework (WinForms DataBinding) microsoft.public.dotnet.framework.windowsforms.databinding


Discuss BindingSource bound type. in the Dotnet Framework (WinForms DataBinding) forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
bruce.m.pearson@gmail.com
 
Posts: n/a

Default BindingSource bound type. - 11-02-2007 , 07:40 PM






I'm having a tough time figuring out how to get the type that a
binding source is bound to..at least in a consistant manner.

What I have been doing is: (aBS is a BindingSource)
Type aType = aBS.List.GetType();
if (aType.IsGenericType)
{
Type[] typeList = aType.GetGenericArguments();
mBoundType = typeList[0];
}
This works most of the time.
However, on occation, the type of the List is Object(!) not the type
the designer set,i.e.,

this.userBindingSource1.DataSource = typeof(Model.User);

At riun time the type of the list is Object.

Anyone got any ideas?

BP


Reply With Quote
  #2  
Old   
Morten Wennevik [C# MVP]
 
Posts: n/a

Default Re: BindingSource bound type. - 11-04-2007 , 12:22 PM






Hi Bruce,

The BindingSource.List property will be of BindingList<T> if you don't initialize it with a list as DataSource. If you don't initialize it withany object at all, the List will be a BindingList<System.Object>

BindingSource bs = new BindingSource();
//bs.List == List<System.Object>


On Sat, 03 Nov 2007 02:40:52 +0100, <bruce.m.pearson (AT) gmail (DOT) com> wrote:

Quote:
I'm having a tough time figuring out how to get the type that a
binding source is bound to..at least in a consistant manner.

What I have been doing is: (aBS is a BindingSource)
Type aType = aBS.List.GetType();
if (aType.IsGenericType)
{
Type[] typeList = aType.GetGenericArguments();
mBoundType = typeList[0];
}
This works most of the time.
However, on occation, the type of the List is Object(!) not the type
the designer set,i.e.,

this.userBindingSource1.DataSource = typeof(Model.User);

At riun time the type of the list is Object.

Anyone got any ideas?

BP




--
Happy coding!
Morten Wennevik [C# MVP]


Reply With Quote
  #3  
Old   
bruce.m.pearson@gmail.com
 
Posts: n/a

Default Re: BindingSource bound type. - 11-04-2007 , 07:16 PM



On Nov 4, 10:22 am, "Morten Wennevik [C# MVP]"
<MortenWenne... (AT) hotmail (DOT) com> wrote:
Quote:
Hi Bruce,

The BindingSource.List property will be of BindingList<T> if you don't initialize it with a list as DataSource. If you don't initialize it with any object at all, the List will be a BindingList<System.Object

BindingSource bs = new BindingSource();
//bs.List == List<System.Object

The designer initializes a BS thusly: this.BindingSource1.DataSource =
typeof(Model.User);

This normally initializes the BS.ds to of BindingList<Model.User>;

However, under certaim circumstaces, at run-time it's not; it's
List<System.Object>.

Weird.

BP




Reply With Quote
  #4  
Old   
Morten Wennevik [C# MVP]
 
Posts: n/a

Default Re: BindingSource bound type. - 11-05-2007 , 10:42 AM




I have encountered cases where the design code does not run, or (more likely) somehow overruled by "unknown forces", usually in combination withcomplex third party controls. Try to initialize the bindingsource in the form constructor or load event.


On Mon, 05 Nov 2007 02:16:31 +0100, <bruce.m.pearson (AT) gmail (DOT) com> wrote:

Quote:
On Nov 4, 10:22 am, "Morten Wennevik [C# MVP]"
MortenWenne... (AT) hotmail (DOT) com> wrote:
Hi Bruce,

The BindingSource.List property will be of BindingList<T> if you don't initialize it with a list as DataSource. If you don't initialize it with any object at all, the List will be a BindingList<System.Object

BindingSource bs = new BindingSource();
//bs.List == List<System.Object


The designer initializes a BS thusly: this.BindingSource1.DataSource =
typeof(Model.User);

This normally initializes the BS.ds to of BindingList<Model.User>;

However, under certaim circumstaces, at run-time it's not; it's
List<System.Object>.

Weird.

BP





--
Happy coding!
Morten Wennevik [C# MVP]


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.