473,385 Members | 2,044 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Aligning Columns In a DataGrid

Hey folks,

Got a Windows Form DataGrid that I bind to a dataset. Using the Table
Styles and the Grid Column Styles, I tell it to right align the columns
which have a numeric value (like Excel does).

Problem is, it also right aligns the Column Header/Description in the
process. The client is asking me to prevent this from happening. Is it
possible to right align the data, but left align it's column headers? If
so, how?

Thanks!
Nov 16 '05 #1
1 3137
You need to a custom DataGridTextBoxColumn to always draw the the cell
contents right aligned.

public class RightAlignedDataGridTextBoxColumn : DataGridTextBoxColumn
{
protected override void Paint(System.Drawing.Graphics g,
System.Drawing.Rectangle bounds,
System.Windows.Forms.CurrencyManager source,
int rowNum,
System.Drawing.Brush backBrush,
System.Drawing.Brush foreBrush,
bool alignToRight)
{
base.Paint(g, bounds, source, rowNum, backBrush,
foreBrush, true);
}
}

It does not work if you set the alignment to centered.

Regards,
Phil.

"John Smith" wrote:
Hey folks,

Got a Windows Form DataGrid that I bind to a dataset. Using the Table
Styles and the Grid Column Styles, I tell it to right align the columns
which have a numeric value (like Excel does).

Problem is, it also right aligns the Column Header/Description in the
process. The client is asking me to prevent this from happening. Is it
possible to right align the data, but left align it's column headers? If
so, how?

Thanks!

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Rookie | last post by:
I need to display several columns of numbers in a textbox. I wish to display the columns with the decimal point position aligned vertically. I have found that the # digit placeholders do not...
0
by: Kshitij | last post by:
Hi, I'm having a datagrid. I'm addng the columns at runtime to the datagrid.But the problem comes during sorting.It doesn't enable the sort column link.Any help on this. Here is my code. ...
11
by: Jon Davis | last post by:
I have a Windows Forms app in which I have a DataGrid control. I have a custom class that has several properties exposed, and I have made this class, or a collection thereof, the DataSource of the...
0
by: Paul | last post by:
Hi I have a datagrid with two different hyperlink columns. The columns open up a new window as the target is set to _blank for both. The windows are different sizes (one large, one small) and I...
1
by: ypul | last post by:
Hi , Getting to the point directly, my query output doesnt have fixed columns , so I choosed "autogenerate columns" datagrid. I assign this dataset to my datagrid, but now I want my data should...
5
by: Jay Villa | last post by:
Is it possible to update only few columns in datagrid during OnUpdateCommand event ? If so, could you help me .... -thanks Jay
1
by: andrewcw | last post by:
The only time the Mouse_Click event is firing for the DataGrid in my application is when I click on a column, What event should I be trapping ? Mouse Down ?? Thanks
3
by: CharlesA | last post by:
Hi folks, I really need help with the following scenario, I'm going to describe as well as a I can what the setup is and what I can't understand I'm using the framework 1.1 using ASP.net with...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.