By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,671 Members | 1,567 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,671 IT Pros & Developers. It's quick & easy.

Bindingsource.datasource Error in desing

P: n/a
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

Jun 27 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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<MySubClassMyListProperty
{
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
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.