Windows Form column DataGridView alignment problem

Posted on 2007-10-02
Medium Priority
Last Modified: 2008-05-14

I have a Windows C# form, contains DataGridView, this Datagrid displays 5 columns, 2 columns should be displayed left aligner and three columns should displayed in Middle ,, i have set the alignment property to cause this ,, when the form is loaded changed dont take effect ,, until i click on one of the column and sort by!

Any one have any idea?
Question by:Abu Hamdan
1 Comment
LVL 22

Accepted Solution

JimBrandley earned 2000 total points
ID: 19998699
If you set the initial properties on the columns before you assign the cell template, the settings propagate to the initial display. For example:

// Finally, add the elapsed Time column
newColumn = new DataGridViewTextBoxColumn();
newColumn.Name = "Elapsed ms";
newColumn.HeaderText = "Elapsed ms";
newColumn.ValueType = typeof(string);
newColumn.FillWeight = 5;
newColumn.DefaultCellStyle.Alignment = DataGridViewContentAlignment.BottomLeft;
cell = new DataGridViewTextBoxCell();
newColumn.CellTemplate = cell;
mElapsedTimeIndex = 6;


Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

864 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