Ice725 Posted March 13, 2006 Posted March 13, 2006 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: 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"); } Quote
Ice725 Posted March 14, 2006 Author Posted March 14, 2006 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: //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: //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? Quote
Ice725 Posted March 14, 2006 Author Posted March 14, 2006 Resolved: I needed to set the TableName to "Clients" and then set the MappingName of the TableStyle to "Clients" also. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.