[RESOLVED] Format Grid Column Headers
This code is not formatting the headers?
Code:
private void SetUpHoldTableStyles()
{
DataGridTableStyle ts = new DataGridTableStyle();
ts.MappingName = binding2.DataMember.ToString();
DataGridColumnStyle recordid = new DataGridTextBoxColumn();
recordid.MappingName = "RecordID"; //column 0
recordid.HeaderText = "#";
recordid.Width = -1;
ts.GridColumnStyles.Add(recordid);
DataGridColumnStyle customername = new DataGridTextBoxColumn();
customername.MappingName = "CustomerName";
customername.HeaderText = "Name";
customername.Width = 100;
ts.GridColumnStyles.Add(customername);
DataGridColumnStyle checkdate = new DataGridTextBoxColumn();
checkdate.MappingName = "CheckDate";
checkdate.HeaderText = "Date";
checkdate.Width = 20;
ts.GridColumnStyles.Add(checkdate);
DataGridColumnStyle paymenttype = new DataGridTextBoxColumn();
paymenttype.MappingName = "PaymentType";
paymenttype.HeaderText = "#";
paymenttype.Width = -1;
ts.GridColumnStyles.Add(paymenttype);
dgHolds.TableStyles.Clear();
dgHolds.TableStyles.Add(ts);
}
It is called from this snippet of code.
Code:
DataSet ds = new DataSet();
ds = client.GetHoldsHeader(strCompanyNum);
DataTable dt = ds.Tables[0];
if (dt.Rows.Count > 0)
{
//fill datagrid on the pnlHolds
//dgHolds.DataSource = dt.DefaultView;
binding2 = new BindingSource();
binding2.DataSource = ds;
binding2.DataMember = "srmfthdr";
dgHolds.DataSource = binding2;
SetUpHoldTableStyles();
}
There are rows returned and it does execute the SetUpHoldTablesStyles(). Any ideas what I have incorrect?
THanks
Re: Format Grid Column Headers
you should call SetUpHoldTableStyles() before setting the datasource. I'm not able to check that right now but that should be the problem.
Re: Format Grid Column Headers
Actually, when you define a style, don't you need to tell it which style you want to use? As I understand it, you can define multiple styles, then change the active style by selecting which one you want to use.
-tg
Re: Format Grid Column Headers
Here's a working demo, posted in this same forum.
techgnome, i think he did define when using
Code:
paymenttype.MappingName = "PaymentType";
ts.GridColumnStyles.Add(paymenttype);
and
dgHolds.TableStyles.Add(ts);
Re: Format Grid Column Headers
right... I get that the style is DEFINED... I see that... but let's say I define and add three styles... how does the grid know which one to use? That was the point I was trying to make.
-tg
Re: Format Grid Column Headers
my bad, i didn't know that you could switch style after displaying the grid and binding the datasource
one thing i know, if there is one only style, and the MappingName is according to the sql columns name, it will work fine. But only if you set the style before binding data. Else it will be ignored.
Re: Format Grid Column Headers
So the two things I need to be doing are:
1. Set the table style before binding the data
2. Make sure the tablestyle are mapped using the correct field names? (Is this case sensitive?)
Thanks........
Re: Format Grid Column Headers
1 - right
2 - mandatory; not sure but you should respect upper and lower case.
Re: Format Grid Column Headers
Still not working. I went through an made sure everything was spelled and cased correctly, they are. Also am calling the table style set up before. I have this working for a 'new' record. But we need to be able to bring in a 'hold' record to make changes to it before moving the ticket on. When the detail is displayed it still is showing all the fields in the grid, but I want only four to show and with the readable header text...........TDQWERTY I used your sample link to help me build the first grid but the second is not working?
Re: Format Grid Column Headers
what do you mean by new record?
Re: Format Grid Column Headers
I will post what I changed to make it work when I get bcak to that project.
Re: Format Grid Column Headers
I was incorrectly spelling some of the names. The characters were correct but not the Upper/Lower case. Thanks to all for help.
Re: [RESOLVED] Format Grid Column Headers