开发者

How do I style Windows.Forms.Datagrid numbers to show like Excel?

开发者 https://www.devze.com 2022-12-21 00:01 出处:网络
I want my datacolumns in my Windows.Forms.Datagrid to show like Excel, 开发者_StackOverflowred for negative numbers in brackets, and black for positive numbers.

I want my datacolumns in my Windows.Forms.Datagrid to show like Excel, 开发者_StackOverflowred for negative numbers in brackets, and black for positive numbers.

Also i want to right align the cells, but left align the header. Is this possible?


Something like this should work for alignment:

var cellStyle = new System.Windows.Forms.DataGridViewCellStyle()
cellStyle.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleRight
dataGridColumn.DefaultCellStyle = cellStyle 

For coloring you should probably handle some datagrid paint event and select different DataGridViewCellStyle for negative numbers.

0

精彩评论

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