默认全部是左对齐,我想让其中2列数字列设置成右对齐。列表头对齐方式不变!

解决方案 »

  1.   


            private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
            {
                if (e.RowIndex > -1)
                {
                    if (e.ColumnIndex == 0 || e.ColumnIndex == 1)
                        e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                }
            }
      

  2.   

        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            Width="469px">
        <Columns>
        <asp:BoundField  HeaderText="用户姓名" DataField="username" ItemStyle-HorizontalAlign="Right" />
        <asp:BoundField HeaderText="城市名" DataField="city" >
          <ItemStyle HorizontalAlign="Right" />
        </asp:BoundField>
        </Columns>
        </asp:GridView>两种方式都可以