Solved

DataGrid styling problems

Posted on 2003-11-17
5
394 Views
Last Modified: 2010-04-16
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.
0
Comment
Question by:_WolfyUK
  • 2
  • 2
5 Comments
 
LVL 4

Expert Comment

by:Tonylmiller
ID: 9767664
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?
0
 

Author Comment

by:_WolfyUK
ID: 9769609
It's not applying any formatting.
0
 
LVL 4

Accepted Solution

by:
Tonylmiller earned 75 total points
ID: 9770688
Are you sure your data table name is "Order"?
You didn't include your databinding statement, so I can't tell for sure.
0
 
LVL 7

Expert Comment

by:jj819430
ID: 9771515
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.
0
 

Author Comment

by:_WolfyUK
ID: 9772466
d'oh!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question