DataGrid TableStyles

Jun 3 2004 3:16 AM
hi. I've got a dataset with mutliple datatables with relations between them and a datagrid. When I navigate from one table to another from the datagrid according to the relations, I want to recreate the tablestyles of the datagrid in order to replace some (by default) textbox columns with custom dropdown list columns. The thing is that it works ok when displaying the first time and when navigating to a child table, but when I hit the back button, wvwn though the style gets created and added to the tablestyle list, the datagrid does not update its layout (the data within gets updated). here is a code sample: //-------------------------------------------------------------------- // this procedure gets called with // - tbName : table name of the DataTable from the datagrid that is the actual source of the display // - member : the relation or the datatable that the datagrid displays // - the datagrid that we're talking about private void makeStyleForGrid(string tbName, string member, DataGrid dg) { // I create a new tablestyle DataGridTableStyle ts = new DataGridTableStyle(); ts.MappingName = tbName; ts.RowHeadersVisible = true; ts.DataGrid = dg; // i iterate through the column of the table tbName for (int i=0; i < dataSet11.Tables[tbName].Columns.Count; i++) { // depending on the column name I add a dropdown column or a default column if (dataSet11.Tables[tbName].Columns[i].ColumnName == "ID_grad" && !dataSet11.Tables[tbName].Columns[i].AutoIncrement) { DropDownDataColumn dc = new DropDownDataColumn(); dc.myComboBox.DisplayMember = "Nume"; dc.myComboBox.ValueMember = "ID_Grad"; dc.MappingName = "ID_Grad"; dc.HeaderText = "Grad"; dc.myComboBox.DataSource = dataSet11.Tables["grade"].DefaultView; if (dataSet11.Tables[tbName].Columns[i].ReadOnly) dc.myComboBox.Enabled = false; ts.GridColumnStyles.Add(dc); } else if (dataSet11.Tables[tbName].Columns[i].ColumnName == "ID_tester" && !dataSet11.Tables[tbName].Columns[i].AutoIncrement) { DropDownDataColumn dc = new DropDownDataColumn(); dc.myComboBox.DisplayMember = "numesiprenume"; dc.myComboBox.ValueMember = "ID_Angajat"; dc.MappingName = "ID_Tester"; dc.HeaderText = "Tester"; dc.myComboBox.DataSource = dataSet11.Tables["angajati"].DefaultView; if (dataSet11.Tables[tbName].Columns[i].ReadOnly) dc.myComboBox.Enabled = false; ts.GridColumnStyles.Add(dc); } else if (dataSet11.Tables[tbName].Columns[i].ColumnName == "ID_concurent" && !dataSet11.Tables[tbName].Columns[i].AutoIncrement) { DropDownDataColumn dc = new DropDownDataColumn(); dc.myComboBox.DisplayMember = "numesiprenume"; dc.myComboBox.ValueMember = "ID_Concurent"; dc.MappingName = "ID_Concurent"; dc.HeaderText = "Concurent"; dc.myComboBox.DataSource = dataSet11.Tables["concurenti"].DefaultView; if (dataSet11.Tables[tbName].Columns[i].ReadOnly) dc.myComboBox.Enabled = false; ts.GridColumnStyles.Add(dc); } else if (dataSet11.Tables[tbName].Columns[i].ColumnName == "numesiprenume") { DataGridTextBoxColumn tx = new DataGridTextBoxColumn(); tx.MappingName = dataSet11.Tables[tbName].Columns[i].ColumnName; tx.HeaderText = dataSet11.Tables[tbName].Columns[i].ColumnName; tx.Width = 0; ts.GridColumnStyles.Add(tx); } else { DataGridTextBoxColumn tx = new DataGridTextBoxColumn(); tx.MappingName = dataSet11.Tables[tbName].Columns[i].ColumnName; tx.HeaderText = dataSet11.Tables[tbName].Columns[i].ColumnName; if (tx.MappingName.StartsWith("ID")) tx.ReadOnly = true; ts.GridColumnStyles.Add(tx); } } // i clear the existing table styles dg.TableStyles.Clear(); // add my own dg.TableStyles.Add(ts); // re-specify the datamember dg.DataMember = member; // and re-specify the datasource dg.DataSource = dataSet11; // and finally invalidate to force repaint dg.Invalidate(true); } //------------------------------------------------------------------- so basically at first the grid displays correctly, then, when I go from a parent table to a child table, it works, but when I go back it doesn't (though the child gets rendered correctly if I go there again) thanks for any help

Answers (1)