|
I have a Windows form for accounts/products. There are three tabs, the first (LIST) has a datagrid with account number and name, the second (EDIT) has text boxes for account data and a datagrid listing products, the third (PRODUCTS) contains textboxes for product data. The account table is bound to the datagrid on the LIST tab and the textboxes on the EDIT tab. The product table is bound to the datagrid on the EDIT tab and textboxes on the PRODUCTS tab. If I am on the PRODUCTS tab adding products, click the EDIT tab, then the PRODUCTS tab again to try adding more products, the new products are no longer going to the table. It's almost like the controls are no longer bound to the table. They don't give any error and the display shows the last product for that account prior to tabbing to EDIT screen. The only coding executed when changing tabs are for enabling/disabling buttons. Hope this all makes sence to somebody. Thanks for any help you can provide.
I have removed the tabs and put everything on one screen and removed the datagrids. The screen now just contains text boxes and navigation buttons. The problem still occurs when navigating to different accounts while adding products. Is there anything that would cause currencymanager to lose track of where it's at? Any ideas? | | MigrationUser 1 Thursday, January 22, 2004 9:31 PM | I'm assuming you are using relations for the related tables right? and set the datamember to the relation?
I'm trying to visualize what you have maybe you can explain without the controls how the data is structured.
Now I'm guessing here that you have text boxes bound to the same table that you have the data grid bound too right?
Ok you need to make sure you bind everything the same.
For example
datagrid1.datasource = dataset1.tables("Hello")
Is not the same as
datagrid1.datasource = dataset1 datagrid1.datamember = "Hello"
They will cause different currencymanagers to be created.
Ok and when binding the controls if you go direct to the datatable out side of the dataset it will be different then going to the dataset then to the data table then to the datacolumn.
For example when looking at the datasources when adding the binding you will see dataset1 datatable1 datatable2
You will want to go to dataset1 then navigate to datable1 then to the column dataset1 datatable1 datacolumn
Your data binding should look like
textbox1.databindings.add(new binding("Text",dataset1,"datatable1.datacolumn1"))
not
textbox1.databindings.add(new binding("text",datatable1,"datacolumn"))
So you have to be the same with the data grid as well as the textboxes in order for them to work. so be careful.
Hope this helps. | | MigrationUser 1 Friday, January 23, 2004 12:00 AM | I am using relations between the Accounts and Products tables. The binding for text boxes look like:
Me.txtContract.DataBindings.Add(New Binding("Text", Me.objdsAccount, "Account.relAccountProduct.Contract"))
The binding for the datagrids look like:
Me.DataGrid1.DataMember = "Account" Me.DataGrid1.DataSource = Me.objdsAccount3
Me.grdProduct.DataMember = "Account.relAccountProduct" Me.grdProduct.DataSource = Me.objdsAccount3
Do I need to set a currencymanager for both the account and product tables or will the currencymanager setup using the binding code above take care of that? I have read quite a bit about currencymanager, but nothing I have read talks much about how it works with relations. Here is the code I use to navigate the account and product data:
Private Sub btnNavFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNavFirst.Click Me.BindingContext(objdsAccount3, "Account").Position = 0 Me.objdsAccount3_PositionChanged() End Sub
Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click Me.BindingContext(objdsAccount3, "Account").Position = Me.BindingContext(objdsAccount3, "Account").Count - 1 Me.objdsAccount3_PositionChanged() End Sub
Private Sub btnNavPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNavPrev.Click Me.BindingContext(objdsAccount3, "Account").Position = (Me.BindingContext(objdsAccount3, "Account").Position - 1) Me.objdsAccount3_PositionChanged() End Sub
Private Sub btnNavNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNavNext.Click Me.BindingContext(objdsAccount3, "Account").Position = (Me.BindingContext(objdsAccount3, "Account").Position + 1) Me.objdsAccount3_PositionChanged() End Sub
Private Sub btnNavFirst2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNavFirst2.Click Me.BindingContext(objdsAccount3, "Account.relAccountProduct").Position = 0 Me.objdsAccount3_PositionChanged2() End Sub
Private Sub btnLast2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast2.Click Me.BindingContext(objdsAccount3, "Account.relAccountProduct").Position = Me.BindingContext(objdsAccount3, "Account.relAccountProduct").Count - 1 '(Me.objdsAccount3.Tables("Account.relAccountProduct").Rows.Count - 1) Me.objdsAccount3_PositionChanged2() End Sub
Private Sub btnNavPrev2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNavPrev2.Click Me.BindingContext(objdsAccount3, "Account.relAccountProduct").Position = (Me.BindingContext(objdsAccount3, "Account.relAccountProduct").Position - 1) Me.objdsAccount3_PositionChanged2() End Sub
Private Sub btnNavNext2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNavNext2.Click Me.BindingContext(objdsAccount3, "Account.relAccountProduct").Position = (Me.BindingContext(objdsAccount3, "Account.relAccountProduct").Position + 1) Me.objdsAccount3_PositionChanged2() End Sub
Thanks for your help, Joe | | MigrationUser 1 Friday, January 23, 2004 10:36 AM | Looks about right, are you still having a problem?
Also I hope you know this line is wrong
Me.txtContract.DataBindings.Add(New Binding("Text", Me.objdsAccount, "Account.relAccountProduct.Contract"))
since the ds name is different everywhere else and it should be.
Me.txtContract.DataBindings.Add(New Binding("Text", Me.objdsAccount3, "Account.relAccountProduct.Contract"))
Let me know | | MigrationUser 1 Friday, January 23, 2004 12:43 PM | Sorry, that was a typo. It's correct in the program.
It still does not work correctly. I should let you know that I also have radio buttons with the binding setup as:
Me.RadioButton5.DataBindings.Add(New Binding("Checked", Me.objdsAccount3, "Account.relAccountProduct.ShopYN"))
and a combobox with binding as:
Me.ComboBox1.DataBindings.Add(New Binding("SelectedValue", Me.objdsAccount3, "Account.relAccountProduct.Category"))
They lool correct to me. One thing I have noticed is that if I get to the point where it does not want to take the new product, and I look back at the product datagrid (Edit tab), it is on a different row from what is showing on the Products tab.
Any ideas?
| | MigrationUser 1 Friday, January 23, 2004 2:52 PM | How are you adding the records? is it via the currenctymanager or a grid, I'm having problems visualizing what you have as an issue.
Now I assume you have this one tab (edit???) and you then have it set on some record right? is that a new record? if you switch over to another control like the products grid (which I guess is related to some table on the edit tab) and you don't do an endcurrentedit before going to a relation then it will fail, pretty much like how you describe it, it will go back a record and your new record disappears. You must end current edit (via the currencymanager) before switching to another child table
parent table Child table
make sure endcurrenteidt is called in parent then go to child and all should be well.
You can do the endcurrentedit in the Tabchangedevent.
| | MigrationUser 1 Friday, January 23, 2004 4:16 PM | This is the code for my add button:
Me.BindingContext(objdsAccount3, "Account.relAccountProduct").EndCurrentEdit() Me.BindingContext(objdsAccount3, "Account.relAccountProduct").AddNew() Dim dtAccount As dsAccount3.AccountDataTable = objdsAccount3.Account Dim drAccount As dsAccount3.AccountRow drAccount = dtAccount.FindByNumber(CType(Me.editNumber.Text, Integer)) Me.editProdCRPer.Text = drAccount.CRPer.ToString
The FindByNumber for the account grabs the account row to set a default CRPer (% of credit earned) field in the product row.
The program is for account & product setup. The top of the screen has account name and number with navigation buttons. Below that are three tabs. The first is LIST which is a datagrid (readonly) with Account names and numbers. The second is EDIT which contains text boxes and a combo box for account data and a datagrid (readonly) with product numbers, desc & qty. The third is PRODUCTS which contains text boxes, combo boxes & radio buttons for product information. This tab also has the navigation buttons for the products. The datagrids are just used for navigation and the problem still occurs after removing them. The problem is when I am in PRODUCTS and add a product and save. Then if I change accounts using navigation buttons or tab to LIST or EDIT then back to PRODUCTS, the next add will work, but adds after that will fail and it will display the last good one. Here is the code in my save button:
Dim iPosition As Integer iPosition = Me.BindingContext(objdsAccount3, "Account.relAccountProduct").Position() Try Me.UpdateDataSet() Me.BindingContext(objdsAccount3, "Account.relAccountProduct").Position = iPosition MessageBox.Show("Product Saved!!") Catch eUpdate As System.Exception MessageBox.Show(eUpdate.Message) End Try
Does this help any? Thanks again for looking at this. I am fairly new to VB.NET and have alot to learn. | | MigrationUser 1 Friday, January 23, 2004 7:36 PM | AHHHH!!!!!!!!!!
You broke the it!!
LOL
Ok you are making changes to the account talbe position afte you have did an add new here.
Me.BindingContext(objdsAccount3, "Account.relAccountProduct").AddNew()
Since it changes position it will auto cancel the addnew of the relationship.
There is your problem, if you need to find a record before adding new, you should do it before. You see the add record is a tempory position, once you change position on a parent it will cancel out your add new. You can't go looking for the new added table after the fact because it's gone. Try reordering how you call things. Once the parent is set then you can call addNew, if you change the parent then it won't work. Also another hint is once you are done adding the record, you should call the end current record before trying to move position again (like adding another record).
Hope this helps | | MigrationUser 1 Saturday, January 24, 2004 8:20 AM | You Rock!!!
Thanks for the help!!! I re-arranged the add sub and it is now working. I moved the findbynumber in front of the addnew and also added a account endcurrentedit before the relaccountproduct endcurrentedit.
Old Code:
Me.BindingContext(objdsAccount3, "Account.relAccountProduct").EndCurrentEdit() Me.BindingContext(objdsAccount3, "Account.relAccountProduct").AddNew() Dim dtAccount As dsAccount3.AccountDataTable = objdsAccount3.Account Dim drAccount As dsAccount3.AccountRow drAccount = dtAccount.FindByNumber(CType(Me.editNumber.Text, Integer)) Me.editProdCRPer.Text = drAccount.CRPer.ToString
New Code:
Dim dtAccount As dsAccount3.AccountDataTable = objdsAccount3.Account Dim drAccount As dsAccount3.AccountRow drAccount = dtAccount.FindByNumber(CType(Me.editNumber.Text, Integer)) Me.BindingContext(objdsAccount3, "Account").EndCurrentEdit() Me.BindingContext(objdsAccount3, "Account.relAccountProduct").EndCurrentEdit() Me.BindingContext(objdsAccount3, "Account.relAccountProduct").AddNew() Me.editProdCRPer.Text = drAccount.CRPer.ToString
I still have some other issues that are occuring as I am moving from tab to tab and account to account, but now I know better what to look for. If I still have problems, I'll start a new thread.
Thanks again, Joe | | MigrationUser 1 Saturday, January 24, 2004 10:27 AM | No problem, also remember to use endcurrentedit when you are done adding the record.
Glad to help | | MigrationUser 1 Saturday, January 24, 2004 4:07 PM |
|