|
-
Dec 20th, 2011, 11:43 AM
#1
Thread Starter
Fanatic Member
[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
-
Dec 21st, 2011, 03:19 AM
#2
Fanatic Member
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.
-
Dec 21st, 2011, 09:07 AM
#3
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
-
Dec 21st, 2011, 10:26 AM
#4
Fanatic Member
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);
-
Dec 21st, 2011, 10:33 AM
#5
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
-
Dec 21st, 2011, 11:02 AM
#6
Fanatic Member
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.
-
Dec 21st, 2011, 03:38 PM
#7
Thread Starter
Fanatic Member
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........
-
Dec 22nd, 2011, 03:19 AM
#8
Fanatic Member
Re: Format Grid Column Headers
1 - right
2 - mandatory; not sure but you should respect upper and lower case.
-
Dec 22nd, 2011, 03:58 PM
#9
Thread Starter
Fanatic Member
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?
-
Dec 29th, 2011, 08:27 AM
#10
Fanatic Member
Re: Format Grid Column Headers
what do you mean by new record?
-
Dec 30th, 2011, 10:27 AM
#11
Thread Starter
Fanatic Member
Re: Format Grid Column Headers
I will post what I changed to make it work when I get bcak to that project.
-
Jan 5th, 2012, 05:06 PM
#12
Thread Starter
Fanatic Member
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.
-
Jan 6th, 2012, 08:21 AM
#13
Fanatic Member
Re: [RESOLVED] Format Grid Column Headers
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|