How can I right-align text in a DataGridView column?

前端 未结 5 1962
有刺的猬
有刺的猬 2021-02-01 12:06

How can I right-align text in a DataGridView column? I am writing a .NET WinForms application.

5条回答
  •  借酒劲吻你
    2021-02-01 12:35

    I know this is old, but for those surfing this question, the answer by MUG4N will align all columns that use the same defaultcellstyle. I'm not using autogeneratecolumns so that is not acceptable. Instead I used:

    e.Column.DefaultCellStyle = new DataGridViewCellStyle(e.Column.DefaultCellStyle);
    e.Column.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
    

    In this case e is from:

    Grd_ColumnAdded(object sender, DataGridViewColumnEventArgs e)  
    

提交回复
热议问题