• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 403
  • Last Modified:

DataGrid styling problems


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.AlternatingBackColor = System.Drawing.Color.WhiteSmoke;


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

Thanks in advance.
  • 2
  • 2
1 Solution
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?
_WolfyUKAuthor Commented:
It's not applying any formatting.
Are you sure your data table name is "Order"?
You didn't include your databinding statement, so I can't tell for sure.
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.
_WolfyUKAuthor Commented:

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now