Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

datagrid tablestyles

Status
Not open for further replies.

DaZZleD

Programmer
Oct 21, 2003
886
US
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:
Code:
[i]// 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[/i]
		private void makeStyleForGrid(string tbName, string member, DataGrid dg)
		{
[i]// I create a new tablestyle[/i]
			DataGridTableStyle ts = new DataGridTableStyle();
			ts.MappingName = tbName;
			ts.RowHeadersVisible = true;
			ts.DataGrid = dg;
			
[i]// i iterate through the column of the table tbName[/i]
			for (int i=0; i < dataSet11.Tables[tbName].Columns.Count; i++)
			{
[i]// depending on the column name I add a dropdown column or a default column[/i]
				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]// i clear the existing table styles[/i]
			dg.TableStyles.Clear();
[i]// add my own[/i]
			dg.TableStyles.Add(ts);
[i]// re-specify the datamember[/i]
			dg.DataMember = member;
[i]// and re-specify the datasource[/i]
			dg.DataSource = dataSet11;
[i]// and finally invalidate to force repaint[/i]
			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
 
Maybe you need to clear Column Styles first.
ts.TableStyles.Clear();


________
George, M
Searches(faq333-4906),Carts(faq333-4911)
 
I always create a new TableStyles so there should be no need to clear the grid columns styles
Code:
DataGridTableStyle ts = new DataGridTableStyle();

and I also clear the datagrid's table styles before adding the new one...


anyway thanks...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top