Databinding textfield in a master detail relation
To all
I'm creating a character database for when I play Dungeons and Dragons (pencil and paper version).
The problem that I'm currently experiencing is when binding a datafield to a field in a master - detail - detail relationship, the information is for the first record in the table and doesn't update when scrolling the ClassSkills detail table.
Following is the relationships for the 3 tables.
Table Relation Class
ClassSkills One to Many based on ClassName
MasterSkillList One to One based on SkillName
Class (Displayed in Datagrid)
|
>ClassSkills (Displayed in Datagrid)
|
>MasterSkillList (Displayed in textboxes)
-
Following is the binding statement that I'm using.
Me.rtfSkillDescription.DataBindings.Add("RichText", DsClass1, "MasterSkillList.SkillDescription")
Thanks
David Davis
This may or may not be the problem, but try the other syntax for specifying databinding:
| |
Me.rtfSkillDescription.DataBindings.Add("RichText", DsClass1.Tables("MasterSkillList"), "SkillDescription")
|
You have to make sure you setup all your Bindings using the same data binding syntax. For example, you're ClassSkills DataGrid should be bound as follows:
| | Me.ClassSkillsDataGrid.DataSource = DsClass1 Me.ClassSkillsDataGrid.DataMember = "MasterSkillList" |
The following won't work as it will generate a different CurrencyManager:
| | Me.ClassSkillsDataGrid.DataSource = DsClass1.MasterSkillList |
Your Class DataGrid should be bound as follows:
| | Me.ClassDataGrid.DataSource = DsClass1 |
Joe Stegman
The Windows Forms Team
Microsoft Corp.
This posting is provided "AS IS" with no warranties, and confers no rights.
Joe,
I don't think one or the other method of binding is right or wrong, I just think you need to be consistent and use the same syntax for both, right?
So, in other words, if you bound your DataGrid with:
| |
Me.ClassDataGrid.DataSource = DsClass1
|
Then you have to use:
| |
Me.rtfSkillDescription.DataBindings.Add("RichText", DsClass1, "MasterSkillList.SkillDescription")
|
But if you bound your grid with:
| |
Me.ClassDataGrid.DataSource = DsClass1.Tables("MasterSkillList")
|
Then you can use this:
| | Me.rtfSkillDescription.DataBindings.Add("RichText", DsClass1.Tables("MasterSkillList"), "SkillDescription")
|
Right? I just wanted to clarify this for others ....
Correct - you need to be consistent in order for this to work.
Joe Stegman
The Windows Forms Team
Microsoft Corp.
This posting is provided "AS IS" with no warranties, and confers no rights.
Joe
I think I explained my problem wrong.
Let me try again. I will only use a Master - Detail (as it's the same problem)
I display the some of the Class Information is a datagrid and textboxes. The databindings work correctly and display the information for the given Class.
I display the Class Skill Name in a datagrid and the information changes when the Class changes. When I databind the Class Skill table to textboxes and scroll the Class Skills datagrid, the textboxes (bound to the same data source as the grid) do not update with the correct information. The only thing that is displayed in the textboxes is the first record from the Class Skills table (not even the correct class).
I will post a message on the http://lab.msdn.microsoft.com/productfeedback/ page to see if this is a bug in VS 2003
David Davis
David,
Did you try what both Joe and I suggested? I still think you're mixing and matching your DataBinding.
How about posting all the relevant code for both your DataGrid and your textbox.
I realize it may not seem obvious, but even though your TextBox binding is setup correctly, it will not stay in sync with your DataGrid if it is not specified the same way as the DataGrid. For example, suppose you have a DataSet (DataSet1) with a table (Table1) with a Column (Column1). If you bind your DataGrid as follows:
DataGrid1.DataSource = DataSet1
DataGrid1.DataMember = "Table1"
In order to keep you TextBox in sync, you need to bind your TextBox as follows:
TextBox1.DataBindings.Add("Text", DataSet1, "Table1.Column1")
If you bind your DataGird like this:
DataGrid1.DataSource = DataSet1.Table1
Then you need to bind your TextBox like this:
TextBox1.DataBindings.Add("Text", DataSet1.Table1, "Column1")
If you bind your DataSet one way and the TextBox the other, then you will see the results you are seeing.
Joe Stegman
The Windows Forms Team
Microsoft Corp.
This posting is provided "AS IS" with no warranties, and confers no rights.
I think I finally figured out the correct question to ask.
When I bind datagrids I usually do it through the properties window (not code) and bind the textboxes through code. Doing the binding via the window I have access to the data relation for the child table, (which is why the child grid works correctly).
If possible how do I bind the textboxes to the data relation for the child table.
Thanks
David Davis
Using "dot" notation - like this:
control.DataBindings.Add("Property", Class, "ClassSkills.MasterSkillList.Column")
Joe Stegman
The Windows Forms Team
Microsoft Corp.
This posting is provided "AS IS" with no warranties, and confers no rights.
Joe
Here is what I finally ended up with
Me.txtSpellName.DataBindings.Add("EditValue", DsClass1, "chrClass.drchrClassSpellsKnown.drMasterSpellList.SpellName")
This was the first time I was trying to bind textboxes to a data relation.
Thanks for all the help
David Davis