9ppel wrote:
Otis wrote:
I think it was/is a bit confusing what form type you're working with as you mentioned 'Object datasource' which is an asp.net control.
OK, sorry about that.
What I ment was that I used "Add New Datasource" under the menu Data in VS05 and then chose "Object", not "Database" or "Web Service" as data source. I then choose Data/Show Data Sources, which gives me the window with "Data Sources". From here I drag and drop some fields from the CustomerEntity into the Windows Form.
I just don't understand why I can't get this working, it should really be "The hello world" of database applications
haha
ok, I now understand what's going on
Ok, here's the deal. When you follow these steps you're describing, the winforms designer will setup your controls, but not with instances of the type(s) you dragged onto the form (e.g. CustomerEntity). It will setup the controls with TYPE definitions of the type. When you go into the form1.designer.cs sourcecode, you'll see in the initializecomponent routine something like:
this.customerEntityBindingSource.DataSource = typeof(Northwind.EntityClasses.CustomerEntity);
(I created a winforms app, dragged a customer entity from the datasources window in detail mode onto the form, and got the navigator and bindingsource.)
This means, the whole form is setup with a type, instead of a real instance.
Now, what you should do is this.
In your form code, create a CustomerCollection instance and if you want to edit existing data, load it first, like I've done in the code below:
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
CustomerCollection customers = new CustomerCollection();
// get all customers
customers.GetMulti(null);
// bind collection to bindingsource to show them in the form.
customerEntityBindingSource.DataSource = customers;
}
}
}
When you now fire up the form, you'll see existing data and you can add new entities, edit existing ones etc.
Saving the data isn't enabled. This is natural, as the navigator obviously doesn't know how to save data. So you click the disk button in the navigator in design view of the form, and go to properties, there you'll see it's disabled. Make Enabled = true, and double click the disk button. An event handler is created. In THERE you'll save the data:
((CustomerCollection)customerEntityBindingSource.DataSource).SaveMulti();
What you can also do, is bind an event handler to customers.ListChanged event, and in there make the save button enabled/disabled.
Good luck