Solved

DataGrid styling problems

Posted on 2003-11-17
5
387 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now