Results 1 to 7 of 7

Thread: datagrid cellstyle alignment

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2008
    Posts
    778

    datagrid cellstyle alignment

    Hello,
    I am trying to change the datagrid cellstyle alignment of a column in the designer. I set it to middle right but then I run it and it still aligned to the left. I have a lot of datagrids in my application but there are few that doesn't accept any alignment settings which I don't understand at all, can't see any reason, I been looking through the options if there is anything but can't find anything.
    I just need one column of cells to be aligned to the right
    whatever I do all of the columns are aligned left and there is an option in the defaultcellstyle that is sat to middle left, but when I try to change it to Not Set it doesn't change.
    Any advice?
    Thanks

  2. #2

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2008
    Posts
    778

    Re: datagrid cellstyle alignment

    well I can't change it at run time. I am not sure what means bound datagrid, but these are normal datagrids that a fill with data from the database, that's all.

  4. #4
    Hyperactive Member jazFunk's Avatar
    Join Date
    Dec 2008
    Location
    Palm Harbor
    Posts
    407

    Re: datagrid cellstyle alignment

    Here's how I do it:

    vb Code:
    1. ' Set Align-MiddleRight object
    2. Dim objAlignMiddleRightCellStyle As New DataGridViewCellStyle()
    3. objAlignMiddleRightCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight


    Then apply this object to the DataGridView cell:


    vb Code:
    1. Me.DataGridView1.Columns(2).DefaultCellStyle = objAlignMiddleRightCellStyle
    Last edited by jazFunk; Feb 8th, 2010 at 10:57 PM. Reason: typo
    Things I've found useful:
    DateTime.ToString() Patterns | Retrieving and Saving Data in Databases | ADO.NET Data Containers: An Explanation

    Quote of the day from jmcilhinney:
    'Talking about Option Strict and Option Explicit in the same sentence is pointless unless it is to say that they should both be On.'

  5. #5
    Hyperactive Member jazFunk's Avatar
    Join Date
    Dec 2008
    Location
    Palm Harbor
    Posts
    407

    Re: datagrid cellstyle alignment

    Just noticed you asked how to do it in the designer. Not in code, as I provided.

    If your dgv is bound to a Database, through a DataAdapter, DataTable, etc., Then I don't know how to changed the cell styles... except for doing so via code.

    If you've added your Columns through the Designer you can adjust those properties if you click on the little box that comes up when you select the "Columns" property in the Property tool bar. Select the column in question and adjust its DefaultCellStyle property.
    Things I've found useful:
    DateTime.ToString() Patterns | Retrieving and Saving Data in Databases | ADO.NET Data Containers: An Explanation

    Quote of the day from jmcilhinney:
    'Talking about Option Strict and Option Explicit in the same sentence is pointless unless it is to say that they should both be On.'

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2008
    Posts
    778

    Re: datagrid cellstyle alignment

    I have a feeling there is some option or I need to correctly configure the cellstyles, because either in designer or in code nothing is changing. What I can do is copy another datagrid that works fine with those and use it but that won't tell me the cause and I can't see the difference between them that work fine and those that doesn't let me modify the cellstyle.
    Thanks anyway

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Apr 2008
    Posts
    778

    Re: datagrid cellstyle alignment

    I made a sample application with one of my datagrids copied, if anybody can change the defaultcellstyle for one of the columns please tell me how you do it , in code or in designer whichever.
    Thanks
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width