Ideas on a form?

  • Thread starter Thread starter Charles
  • Start date Start date
C

Charles

I am trying to create a form that has two comboboxes that
would do a parent-child relationship, navigates though
the data using both the two comboboxes and four buttons,
able to add, update, and delete from a database, has a
textbox that displays a record number (ie: Record 4 of
10), and displays the child's data in textboxes.

Using the Northwind database for example I would be using
the Categories and Products tables.

I have gone though four revisions of this form and not
have much luck.

Should I go with three datatables? Should I add a
relation between the two database tables? If I add a
relation, how could I get to the data? I guess I am at a
lost on how to best program a form like this.

How would you go about designing and coding a form like
this?

Thank you,
Charles
 
Hi,

First, create a typed dataset with necessary tables and relations. Populate
the dataset from the database then and establish data bindings for the
"parent" controls and "child" controls. DataMember name should be equal to
the data table name for the "parent" controls and it should have a form of
"TableName.RelationName" for the child ones.

To add/remove records, get a reference to the corresponding CurrencyManager
(the Binding plumbing will create two of them - for the parent table and for
the child one) from the form's BindingContext property and use AddNew/Remove
methods.

These are of course only the basics, you will need solid understanding of
how DataBinding works in Windows Forms.
 
Thank you for your reply. I am working though your
message and came up with a question/problem.

The DataMember Property is not a property that is
accessed in a Textbox. Correct? What
would "TableName.RelationName" look like in code. This
is the code that I am defining the Relation and one of
the child DataBindings:

dsInventory.Relations.Add("CategoryProducts", _
dsInventory.Tables("Categories").Columns
("CategoryID"), _
dsInventory.Tables("Products").Columns
("CategoryID"))

VB.NET does not like this part of the
line, "dsInventory.Tables("Categories").CategoryProducts"

txtQuantityPerUnit.DataBindings.Add("Text",
dsInventory.Tables
("Categories").CategoryProducts, "QuantityPerUnit")

Thank you,
Charles


-----Original Message-----
Hi,

First, create a typed dataset with necessary tables and relations. Populate
the dataset from the database then and establish data bindings for the
"parent" controls and "child" controls. DataMember name should be equal to
the data table name for the "parent" controls and it should have a form of
"TableName.RelationName" for the child ones.

To add/remove records, get a reference to the corresponding CurrencyManager
(the Binding plumbing will create two of them - for the parent table and for
the child one) from the form's BindingContext property and use AddNew/Remove
methods.

These are of course only the basics, you will need solid understanding of
how DataBinding works in Windows Forms.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Charles said:
I am trying to create a form that has two comboboxes that
would do a parent-child relationship, navigates though
the data using both the two comboboxes and four buttons,
able to add, update, and delete from a database, has a
textbox that displays a record number (ie: Record 4 of
10), and displays the child's data in textboxes.

Using the Northwind database for example I would be using
the Categories and Products tables.

I have gone though four revisions of this form and not
have much luck.

Should I go with three datatables? Should I add a
relation between the two database tables? If I add a
relation, how could I get to the data? I guess I am at a
lost on how to best program a form like this.

How would you go about designing and coding a form like
this?

Thank you,
Charles

.
 
The code that you changed has four arguments, 'Add' only
accepts three arguments.

If I put in:
dsInventory.Tables("Categories") -Does not use Relations

"Categories.CategoryProducts" -Gives me this error
message, "Cannot bind to property or column
QuantityPerUnit on DataSource."

What table would I use to navigate though the data?

Thank you for your help!

Charles
-----Original Message-----
The code below
txtQuantityPerUnit.DataBindings.Add("Text",
dsInventory.Tables
("Categories").CategoryProducts, "QuantityPerUnit")

should be changed to:

txtQuantityPerUnit.DataBindings.Add("Text",
dsInventory.Tables("Categories"),
"Categories.CategoryProducts", "QuantityPerUnit")

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Charles said:
Thank you for your reply. I am working though your
message and came up with a question/problem.

The DataMember Property is not a property that is
accessed in a Textbox. Correct? What
would "TableName.RelationName" look like in code. This
is the code that I am defining the Relation and one of
the child DataBindings:

dsInventory.Relations.Add("CategoryProducts", _
dsInventory.Tables("Categories").Columns
("CategoryID"), _
dsInventory.Tables("Products").Columns
("CategoryID"))

VB.NET does not like this part of the
line, "dsInventory.Tables ("Categories").CategoryProducts"

txtQuantityPerUnit.DataBindings.Add("Text",
dsInventory.Tables
("Categories").CategoryProducts, "QuantityPerUnit")

Thank you,
Charles


-----Original Message-----
Hi,

First, create a typed dataset with necessary tables
and
relations. Populate
the dataset from the database then and establish data bindings for the
"parent" controls and "child" controls. DataMember
name
should be equal to
the data table name for the "parent" controls and it should have a form of
"TableName.RelationName" for the child ones.

To add/remove records, get a reference to the corresponding CurrencyManager
(the Binding plumbing will create two of them - for
the
parent table and for
the child one) from the form's BindingContext property and use AddNew/Remove
methods.

These are of course only the basics, you will need
solid
understanding of
how DataBinding works in Windows Forms.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

I am trying to create a form that has two comboboxes that
would do a parent-child relationship, navigates though
the data using both the two comboboxes and four buttons,
able to add, update, and delete from a database, has a
textbox that displays a record number (ie: Record 4 of
10), and displays the child's data in textboxes.

Using the Northwind database for example I would be using
the Categories and Products tables.

I have gone though four revisions of this form and not
have much luck.

Should I go with three datatables? Should I add a
relation between the two database tables? If I add a
relation, how could I get to the data? I guess I am at a
lost on how to best program a form like this.

How would you go about designing and coding a form like
this?

Thank you,
Charles







.

.
 
I got it to work!

I now have to work on getting the database updated and
working with the CurrencyManager.

Thank you,
Charles
-----Original Message-----
The code below
txtQuantityPerUnit.DataBindings.Add("Text",
dsInventory.Tables
("Categories").CategoryProducts, "QuantityPerUnit")

should be changed to:

txtQuantityPerUnit.DataBindings.Add("Text",
dsInventory.Tables("Categories"),
"Categories.CategoryProducts", "QuantityPerUnit")

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Charles said:
Thank you for your reply. I am working though your
message and came up with a question/problem.

The DataMember Property is not a property that is
accessed in a Textbox. Correct? What
would "TableName.RelationName" look like in code. This
is the code that I am defining the Relation and one of
the child DataBindings:

dsInventory.Relations.Add("CategoryProducts", _
dsInventory.Tables("Categories").Columns
("CategoryID"), _
dsInventory.Tables("Products").Columns
("CategoryID"))

VB.NET does not like this part of the
line, "dsInventory.Tables ("Categories").CategoryProducts"

txtQuantityPerUnit.DataBindings.Add("Text",
dsInventory.Tables
("Categories").CategoryProducts, "QuantityPerUnit")

Thank you,
Charles


-----Original Message-----
Hi,

First, create a typed dataset with necessary tables
and
relations. Populate
the dataset from the database then and establish data bindings for the
"parent" controls and "child" controls. DataMember
name
should be equal to
the data table name for the "parent" controls and it should have a form of
"TableName.RelationName" for the child ones.

To add/remove records, get a reference to the corresponding CurrencyManager
(the Binding plumbing will create two of them - for
the
parent table and for
the child one) from the form's BindingContext property and use AddNew/Remove
methods.

These are of course only the basics, you will need
solid
understanding of
how DataBinding works in Windows Forms.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

I am trying to create a form that has two comboboxes that
would do a parent-child relationship, navigates though
the data using both the two comboboxes and four buttons,
able to add, update, and delete from a database, has a
textbox that displays a record number (ie: Record 4 of
10), and displays the child's data in textboxes.

Using the Northwind database for example I would be using
the Categories and Products tables.

I have gone though four revisions of this form and not
have much luck.

Should I go with three datatables? Should I add a
relation between the two database tables? If I add a
relation, how could I get to the data? I guess I am at a
lost on how to best program a form like this.

How would you go about designing and coding a form like
this?

Thank you,
Charles







.

.
 
I now have to work on getting the database updated and
working with the CurrencyManager.

Nice to know that :-)

As for the wrong number of arguments in my previous posting, it's just that
I rely too much on IntelliSence which is not an option in a newsreader :-)

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Charles said:
I got it to work!

I now have to work on getting the database updated and
working with the CurrencyManager.

Thank you,
Charles
-----Original Message-----
The code below
txtQuantityPerUnit.DataBindings.Add("Text",
dsInventory.Tables
("Categories").CategoryProducts, "QuantityPerUnit")

should be changed to:

txtQuantityPerUnit.DataBindings.Add("Text",
dsInventory.Tables("Categories"),
"Categories.CategoryProducts", "QuantityPerUnit")

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Charles said:
Thank you for your reply. I am working though your
message and came up with a question/problem.

The DataMember Property is not a property that is
accessed in a Textbox. Correct? What
would "TableName.RelationName" look like in code. This
is the code that I am defining the Relation and one of
the child DataBindings:

dsInventory.Relations.Add("CategoryProducts", _
dsInventory.Tables("Categories").Columns
("CategoryID"), _
dsInventory.Tables("Products").Columns
("CategoryID"))

VB.NET does not like this part of the
line, "dsInventory.Tables ("Categories").CategoryProducts"

txtQuantityPerUnit.DataBindings.Add("Text",
dsInventory.Tables
("Categories").CategoryProducts, "QuantityPerUnit")

Thank you,
Charles



-----Original Message-----
Hi,

First, create a typed dataset with necessary tables and
relations. Populate
the dataset from the database then and establish data
bindings for the
"parent" controls and "child" controls. DataMember name
should be equal to
the data table name for the "parent" controls and it
should have a form of
"TableName.RelationName" for the child ones.

To add/remove records, get a reference to the
corresponding CurrencyManager
(the Binding plumbing will create two of them - for the
parent table and for
the child one) from the form's BindingContext property
and use AddNew/Remove
methods.

These are of course only the basics, you will need solid
understanding of
how DataBinding works in Windows Forms.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

I am trying to create a form that has two comboboxes
that
would do a parent-child relationship, navigates though
the data using both the two comboboxes and four
buttons,
able to add, update, and delete from a database, has a
textbox that displays a record number (ie: Record 4 of
10), and displays the child's data in textboxes.

Using the Northwind database for example I would be
using
the Categories and Products tables.

I have gone though four revisions of this form and not
have much luck.

Should I go with three datatables? Should I add a
relation between the two database tables? If I add a
relation, how could I get to the data? I guess I am
at a
lost on how to best program a form like this.

How would you go about designing and coding a form like
this?

Thank you,
Charles







.

.
 
Would I reference the corresponding CurrencyManager as:

Dim cmCategories As CurrencyManager

cmCategories = CType(Me.BindingContext(dsInventory.Tables
("Categories")), CurrencyManager)

Also it seems like that the Dataset is changed, but can
not get the database updated. How can I get changes
with .GetChanges?

Thanks,
Charles
 
For the parent table, yes. For the child table you would also need to
specify the DataMember name when querying the BindingContext.

As for the DataSet, the modified rows should have their RowStatus equal to
Modified or Added (if you have added new records). However, I've seen
postings in this or another .NET newsgroup that the GetChanges method could
return no rows despite the changes that have been made. I'd say anyway that
this is the first thing to try, and I'd also suggest calling AcceptChanges
on all tables in the DataSet when you've just populated it from the
database.
 
Back
Top