Register  |  Login



Earn money by sharing your knowledge

Quomon shares its advertising revenue with contributing experts that answer questions effectively. Join our community to share your knowledge and earn an income as you go.

Question

Status: Closed Points: 75 Time: 14:28 - Apr 04, 2007  

dustPuppy

how to align the cells in a datagridview to the right in c#.net?

I need to align some of the columns in a datagridview to the right. But I can't find any property to control the alignment. How can i accomplish that?
I'm programming in c#.net (visual studio 2005).

Answer Discussion
Tutorials

 

Q&A System for Websites and Corporate Collaboration

Advertisement

  • Generates significant organic traffic for websites
  • Saves companies money, resources, and time

PeterNZ

Date:: Apr 04, 2007

Time:: 15:59

Either select your DataGridView in thedesigner window and set the property "RowStyle|HorizontalAlign" to "Right" or change the HTML code and add "align=right" to the <td> tags.

Cheers

Peter

dustPuppy

Date:: Apr 04, 2007

Time:: 16:25

thanks, Peter.
I forgot to say that it's windows forms, not asp.net, so the solution doesn't work unfortunately.

PeterNZ

Date:: Apr 04, 2007

Time:: 16:36

Oh sorry, I am deep in ASP.Net development at the moment so my brain was focussed on this! Sorry!

For a windows app, look at RowTemplate property of the GridView component, expand the sub nodes and click on the [...] for DefaultCellStyle. This will open the CellStyle Builder. Set the Alignment property in the Layout section.

Cheers

Peter

dustPuppy

Date:: Apr 05, 2007

Time:: 05:00

thank you Peter, that worked.
I found that the equivalent by code is:

this.dataGridView1.Columns["CustomerName"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;

and the points go to..... Peter!!! :)

Question Answered

This question has been closed, and points have been rewarded to the following experts:

PeterNZ: 75

You're welcome however to comment or give additional information or if you wish, you have the ability to write a Tutorial in the Tutorial Area.

Answer this Question

New User

Email:

Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

Registered User

Username:

Password:

Forgot Your Password?

No tutorials have been submitted yet. Want to be the first?

Answer this Question

New User

Email:

Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

Registered User

Username:

Password:

Forgot Your Password?

Ask a Question

Have a new question? Ask!

You have 100 characters to use



Top .net Experts

View More

Rank

Expert

Points

1.

PeterNZ

885

2.

nidhi

560

3.

rcastagna

488

4.

multani.sarbjit

200

5.

dustPuppy

75

6.

Sergio Costa

50

7.

Zoush

50

8.

manohar.patil

30

9.

xarcus

25

10.

prashanth.guru

20

Become an Expert

Register today to share your knowledge with the community and be recognized and rewarded for your contributions.


Register Here




"Psst, Quomon is a great site. Pass it on."     Tell a Friend  |   Link To Us  |   Save to Delicious  |   Digg! Digg it



Language Options

English:

www.quomon.com

Español:

www.quomon.es