PC Review


Reply
Thread Tools Rate Thread

Bindingsource.datasource Error in desing

 
 
Alhambra Eidos Kiquenet
Guest
Posts: n/a
 
      25th Jun 2008
Hi misters,


I used the Data Sources window to drop a custom object onto the designer
surface. It created a BindingSource and BindingNavigator as a result.

When I open the Properties window on the BindingSource, I see DataSource
property set to the object I created.



However, when I try to dropdown the DataSource property, I get the message:

"Object reference not set to an instance of an object". The title of the
messagebox is "Microsoft Visual Studio".

So I cannot change the DataSource, I went into the designer file and
removed the DataSource property of the BindingSource and went back into the
designer. It showed the DataSource as (none) as I expected.

But the same error message occurs when I try to change the property with the
dropdown box.

What is going on? Any help will be very grateful

Thanks in advance, regards


--
http://www.alhambra-eidos.es/web2005/index.html
www.kiquenet.net
http://www.setbb.com/putainformatica...opic.php?p=843
www.trabajobasura.com/solusoft

 
Reply With Quote
 
 
 
 
Morten Wennevik [C# MVP]
Guest
Posts: n/a
 
      25th Jun 2008
Hi Alhambra,

I'm suspecting the BindingSource is created using a Type as DataSource
instead of an object instance. Designer created BindingSources may need some
manual code to be properly initialized.

I don't know too much about the designer features as I never use it, but it
is easy to create (and in my opinion far easier to use) in code.

Sample code:

public Form1()
{
InitializeComponent();

BindingSource source = new BindingSource(new MyClass(), "MyListProperty");
listBox1.DataSource = source;
listBox1.DisplayMember = "MyProperty";
textBox1.DataBindings.Add("Text", source, "MyProperty");
}

class MyClass
{
private List<MySubClass> _myListProperty = new List<MySubClass>();

public List<MySubClass> MyListProperty
{
get { return _myListProperty; }
set { _myListProperty = value; }
}

public MyClass()
{
MyListProperty.Add(new MySubClass("Hello"));
MyListProperty.Add(new MySubClass("And"));
MyListProperty.Add(new MySubClass("Goodbye"));
}
}

class MySubClass
{
private string myProperty;

public string MyProperty
{
get { return myProperty; }
set { myProperty = value; }
}

public MySubClass(string text)
{
MyProperty = text;
}
}


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


"Alhambra Eidos Kiquenet" wrote:

> Hi misters,
>
>
> I used the Data Sources window to drop a custom object onto the designer
> surface. It created a BindingSource and BindingNavigator as a result.
>
> When I open the Properties window on the BindingSource, I see DataSource
> property set to the object I created.
>
>
>
> However, when I try to dropdown the DataSource property, I get the message:
>
> "Object reference not set to an instance of an object". The title of the
> messagebox is "Microsoft Visual Studio".
>
> So I cannot change the DataSource, I went into the designer file and
> removed the DataSource property of the BindingSource and went back into the
> designer. It showed the DataSource as (none) as I expected.
>
> But the same error message occurs when I try to change the property with the
> dropdown box.
>
> What is going on? Any help will be very grateful
>
> Thanks in advance, regards
>
>
> --
> http://www.alhambra-eidos.es/web2005/index.html
> www.kiquenet.net
> http://www.setbb.com/putainformatica...opic.php?p=843
> www.trabajobasura.com/solusoft
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Datatable as bindingsource datasource John Microsoft ADO .NET 1 3rd Feb 2009 12:22 PM
BindingSource vs DataSource Bresco Microsoft Dot NET Framework Forms 1 26th Jan 2009 08:25 AM
BindingSource set DataSource and DataMember atomically? Doug Crawford Microsoft Dot NET Compact Framework 0 19th Sep 2007 06:55 PM
BindingSource.DataSource - Do I need InvokeRequired? Spam Catcher Microsoft VB .NET 0 29th Jan 2007 09:20 PM
Updating BindingSource.DataSource from non UI thread peancor Microsoft Dot NET Framework 2 19th Apr 2006 02:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:57 AM.