tags:

views:

34

answers:

1

I have a C# winforms database application.

I want to create a custom user control which will go on say an add new customer page. I have my database app all wired up. I have DataTables, and TableAdapters, and other stuff... but I don't see a way to create a custom UI which will bind the windows form controls to an object which I could then use to add to the database. I expected there to be some way that i could drag some table from my dataset onto my form which would add things like textbox's for each column. I know something like this must exists but I just don't know what to call it... things like DataBinding giving me a bunch of examples which show how you could update put like a phone number in a text box when the Custome row in a DataTable is selected.

I want to avoid doing:

public void button1_OnClick() {
  MyDatabase.OrganizationRow r = new MyDatabase.OrganizationRow();
  r.ID = textbox1.Text;
  r.Name = textbox2.Text;
  r.ShortName = textbox3.Text;    

  this.myDatabase.Organization.Rows.Add(o1);
  this.myDatabase.AcceptChanges();
}

Thanks in advance. I'm using .NET 2.0 and VS 2005.

A: 

You can databind the controls to a BindingSource, then call the BindingSource's AddNew method before the user starts entering data and EndEdit when the user clicks save (or add or whatever)

SLaks
How... I want to have things bound automatically. Is there no way?
blak3r
You can drag fields from Server Explorer.
SLaks
I found I could drag fields in Data Sources... but there is no way to like get an object from the collection of windows controls that could be used to add a row to the database. It's mainly useful for displaying data as far as i can tell. I'm still manually doing a bunch of textbox1.text stuff.
blak3r
You can bind the controls to a BindingSource, then call `AddNew` and `EndEdit`, and you won't need to do that.
SLaks