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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Applying Table Style To Grid

Status
Not open for further replies.

litton1

Technical User
Joined
Apr 21, 2005
Messages
584
Location
GB
I am trying to apply a column style to the table (dtTasks) that is displayed in a grid. I don’t think that it has applied as no matter what size I make the first column width it remains the same. The code I am using is as follows:
Code:
System.Windows.Forms.DataGridTableStyle TableStyle1 = new DataGridTableStyle();

TableStyle1.MappingName = "Tasktable";
				
int j=0;
//for(; j<dtTasks.Columns.Count; j++)
//{
DataGridColumnStyle taskNameStyleCol = new DataGridTextBoxColumn();
				
taskNameStyleCol.MappingName = "cs" + dtTasks.Columns[j].ColumnName; 
taskNameStyleCol.Width = 200;					
taskNameStyleCol.HeaderText = dtTasks.Columns[j].Caption; //dc.Caption;
taskNameStyleCol.Alignment = System.Windows.Forms.HorizontalAlignment.Left ;
taskNameStyleCol.ReadOnly = false;
temp = dtTasks.Columns[j].ColumnName;
					
TableStyle1.GridColumnStyles.Add(taskNameStyleCol);
			
dgTask.AlternatingBackColor = Color.Gainsboro;
dgTask.TableStyles.Add(TableStyle1);
				
dgTask.DataSource = dtTasks;
All help appreciated Thx T.

Age is a consequence of experience
 
afiak, setting the datasource resets the datagridtablestyle.

try moving "dgTask.DataSource = dtTasks;" to the beginning of the code.


mr s. <;)

 
Hi, thanks for your reply, sorted it now and that was one of the problems. Also the mapping style (for the column) name did not match the DC name lol, Thx again for your time.

Age is a consequence of experience
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top