|
OK, I have a typed dataset with three tables. Project, Task and Project Task. The ProjectTask table captures the many to many relationship between Project and Task, and has a composite primary key of ProjectID and TaskID, together with some additional fields such as Completed, DateCompleted, etc.
I have a datagrid, which I easily populate with the fields I want, using a tablestyle for the ProjectTask table, and the TaskID, Completed, and DateCompleted fields. So far, so good.
Obviously, the TaskID appearing in the grid is not informative, and I want the actual Task name to appear in the grid. So (trying this both in designer and via code), I add a TaskText Column to the ProjectTask datatable, give it a string datatype, a column name of "TaskText", and an expression of Parent(TaskProjectTask).TaskName. I need to specify the TaskProjectTask data relation because there is also a parent relationship with the Project table. I configure my table column style for the grid to point to TaskText
When I run the app, the columns appear as they should, but the TaskText field is (null). I doublechecked that the Task table was loading and had values. Any ideas? This grid is giving me headaches . . .
Jeff
| | MigrationUser 1 Friday, February 11, 2005 1:45 PM | If you are using Typed DataSets you will most probably need to inherit from the class and add the row later. I gave up on this, beacuse it wasn't that important for me.
However here is the problem and solution for what is going on
Problem: The parent and child functions do not work properly as shown in examples or documnetation.
Workaround: You add the columns or you can try just specifying the Expression after you add the RELATIONSHIP.
The order that worked was:
Create DataSet Add Table1 w/ columns Add Table2 w/ columns Add the Realtionship for these tables
Now add the columns with expression like: Parent(TaskProjectTask)
Hope this helps.
If you find a better solution, please do post.
rythm | | MigrationUser 1 Sunday, February 13, 2005 8:23 PM | To get a column from the parent table, the expression should just be:
ParentTableName.ColumnName
Child columns are access through the relationship name:
ParentTableName.RelationshipName.ChildColumnName
It looks like you just want "Task.TaskName". I'm not sure where "TaskProjectTask" came from... it's not in your example... "ProjectTask" is, but not "TaskProjectTask"... | | MigrationUser 1 Monday, February 14, 2005 5:03 PM | I can't just use the ParentTableName.ColumnName construct here, as ProjectTask has two parent tables, Project and Task. Accordingly, I need to use the Parent(TaskProjectTask).TaskName, to define the relationship I am using. TaskProjectTask is the relationship between Task and ProjectTask. Again, however, I get (null) for the TaskName value.
Jeff | | MigrationUser 1 Tuesday, February 15, 2005 8:58 AM | OK, now I'm really confused. When I check all of the values and attributes of the table columns at run time, the Expression value for the TaskText column is empty. For some reason, the data table is not picking up the expression for the column. Tried adding the expression in code and in the designer.
Jeff | | MigrationUser 1 Tuesday, February 15, 2005 11:23 AM | OK, I got it figured out. I was configuring the new data column, adding the expression and adding it to the data table, then I was filling the table with data. When I moved the code adding the column to the table to a point AFTER filling the data table, it works. I'll have to think about this one for awhile -- seems sorta backwards to me, but at least it works now.
By the way, I confirmed that I cannot simply call Parent.TaskName, due to the multiple relations.
Whew . . . Sometimes MS makes the simplest thing just way too difficult
Jeff | | MigrationUser 1 Tuesday, February 15, 2005 1:27 PM |
|