Link to home
Start Free TrialLog in
Avatar of _WolfyUK
_WolfyUK

asked on

DataGrid styling problems

Hello,

I'm going mad trying to figure out why my DataGrid is not being formatted as I want it to be. I have three columns which I style using a single DataGridTableStyle with DataGridTextBoxColumns for each column's style.

The styling is called from the function AddColumns(), below:

private void AddColumns()
            {

                  DataGridTableStyle tableStyle = new DataGridTableStyle();
                  tableStyle.MappingName = "Order";

                  DataGridTextBoxColumn menuIDColumn = new DataGridTextBoxColumn();
                  menuIDColumn.MappingName = "ItemMenuID";
                  menuIDColumn.HeaderText = "Menu ID";
                  menuIDColumn.Alignment= HorizontalAlignment.Left;
                  menuIDColumn.Width = 10;
                  menuIDColumn.NullText = "";

                  DataGridTextBoxColumn nameColumn = new DataGridTextBoxColumn();
                  nameColumn.MappingName = "ItemName";
                  nameColumn.HeaderText = "Name";
                  nameColumn.Alignment = HorizontalAlignment.Left;
                  nameColumn.Width = 200;
                  nameColumn.NullText = "";

                  DataGridTextBoxColumn priceColumn = new DataGridTextBoxColumn();
                  priceColumn.MappingName = "ItemPrice";
                  priceColumn.HeaderText = "Price";
                  priceColumn.Alignment = HorizontalAlignment.Left;
                  priceColumn.Width = 20;
                  priceColumn.NullText = "";

                  tableStyle.GridColumnStyles.Add(menuIDColumn);
                  tableStyle.GridColumnStyles.Add(nameColumn);
                  tableStyle.GridColumnStyles.Add(priceColumn);

                  tableStyle.AlternatingBackColor = System.Drawing.Color.WhiteSmoke;


                  orderDataGrid.TableStyles.Add(tableStyle);
}

This function is called in the form's constructor, along with row names and data types.

Thanks in advance.
Avatar of Tonylmiller
Tonylmiller

It would be a good start to tell us what the problem is. . .

So what is it not doing correctly?  Is it doing some of the formatting, but not all?
Avatar of _WolfyUK

ASKER

It's not applying any formatting.
ASKER CERTIFIED SOLUTION
Avatar of Tonylmiller
Tonylmiller

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What are you binding to?
Are you pulling this data from say a SQL DB.
If so you need to do the binding.
And you may be doing things out of order.
d'oh!