关于Datagridview格式样式的问题

huangapple go评论59阅读模式
英文:

Question About Datagridview Format Styling

问题

我想在Datagridview列中显示千位分隔符
所以我在Datagridview中添加了一列,然后运行了这段代码,但它对我不起作用。

英文:

i want to Show Thousand Separator in Datagridview Column
So i added One Column in datagridview so i Run this code But It's not working with me
关于Datagridview格式样式的问题

关于Datagridview格式样式的问题

答案1

得分: 1

You need to explicitly specify the column's ValueType if you don't have a DataSource to bind (ex. DataTable) which is the source of the data types as well. Here, you need a column of a numeric type such as Decimal.

So, before you populate the grid or add new rows, do:

With DataGridView2.Columns(0)
    .ValueType = GetType(Decimal)
    .DefaultCellStyle.Format = "#,#.##"
End With

In case the control is bound to DataSource, make sure that the type of the data field/property in question is numeric.

英文:

You need to explicitly specify the column's ValueType if you don't have a DataSource to bind (ex. DataTable) which is the source of the data types as well. Here, you need a column of a numeric type such as Decimal.

So, before you populate the grid or add new rows, do:

With DataGridView2.Columns(0)
    .ValueType = GetType(Decimal)
    .DefaultCellStyle.Format = "#,#.##"
End With

In case the control is bound to DataSource, make sure that the type of the data field/property in question is numeric.

huangapple
  • 本文由 发表于 2023年2月19日 02:46:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/75495599.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定