开发者

datagridview alternatingrow alignment

In my project I read a csv file and store it in a DataTable and then display it in a DataGridView. But I want a column that the values are aligned to the right that is in column 2 so I write:

grigliavenduto.Columns[2].DefaultCellStyle.Alignment = 
                                 DataGridViewContentAlignment.MiddleRight;

But this happens to one row but not the next, a sort of yes no yes no yes no .... so how can I by code to set the alignment to th开发者_JS百科e right of the column AlternatingRowsDefaultCellStyle 2? thanks


I don't think you will be able to specify an alternate style for a specific column, instead can you try the CellFormatting event

void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
    if (e.ColumnIndex == [your index])
    {
      //conditions and then set like e,RowIndex % 2 == 0
                e.CellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
    }
}


You can also set the property: grigliavenduto.Columns[2].AlternatingCellStyle to the same as above, this would probably work.

But I think there should be a property which affects both normal and alternating rows, look at the properties of the DataGridView and play around a bit.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜