Windows Form column DataGridView alignment problem

Posted on 2007-10-02
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

    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

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    755 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

    22 Experts available now in Live!

    Get 1:1 Help Now