DataGrid TableStyle with DataSet

Ice725

Freshman
Joined
Apr 19, 2004
Messages
31
I've created a DataGrid with a TableStyle, I set the datasource of the DataGrid to a DataTable, and it works great. I can see the columns I specified in the TableStyle.

I've loaded another DataTable and linked this new table to the existing table so my datagrid can use the DataRelation object to show these tables in same datagrid.

The problem is, my TableStyle for the Parent is no longer being used. Is it possible to apply a TableStyle in this situation?, If so, how can I go about this?

Here is some code snippets:

Code:
private void MakeDataRelation(){
    // DataRelation requires two DataColumn (parent and child) and a name.
    DataRelation myDataRelation;
    DataColumn parentColumn;
    DataColumn childColumn;
    parentColumn = myDataSet.Tables["ParentTable"].Columns["id"];
    childColumn = myDataSet.Tables["ChildTable"].Columns["ParentID"];
    myDataRelation = new DataRelation("parent2Child", parentColumn, childColumn);
    myDataSet.Tables["ChildTable"].ParentRelations.Add(myDataRelation);
 }
 
 private void BindToDataGrid(){
    // Instruct the DataGrid to bind to the DataSet, with the 
    // ParentTable as the topmost DataTable.
    dataGrid1.SetDataBinding(myDataSet,"ParentTable");
 }
 
I've removed the idea of the DataRelations because I can't seem to get the DataGrid to display the TableStyle if the DataTable is added to a DataSet

Example:

Code:
//Create new DataSet
DataSet myDataSet = new DataSet();

//Get All Clients in Database
tblClients = Client.GetAllClients();

//Add DataTable to DataSet
myDataSet.Tables.Add(tblClient);

//Set DataGrid DataSource
dataGrid1.DataSource = myDataSet.Tables[0];

This does NOT load the TableStyle I've created... But the following code DOES:

Code:
//Get All Clients in Database
tblClients = Client.GetAllClients();

//Set DataGrid DataSource
dataGrid1.DataSource = tblClients;

As soon as I add the table to the DataSet, the TableStyle stops working. Do I need to do something different?
 
Resolved:

I needed to set the TableName to "Clients" and then set the MappingName of the TableStyle to "Clients" also.
 
Back
Top