2016-05-13 159 views
0

我需要帮助格式化这个datagridview中的单个单元格。例如,最后一个单元格需要格式化为小数点后两位。剩余的单元格的方式很好,除了我还需要设置所有单元格的入口限制。例如,油流入口必须介于0到300之间,等等。我很确定我可以确定这一部分。我在格式化单个单元时遇到困难。我在cellformatting事件中尝试了以下代码行,但由于某种原因它不起作用,因为它在Form Load事件后执行的Initialize子例程中工作。在Datagridview中格式化单元格

dgvPresets.Item(1,10)= .Style.Format “0.00”

Datagridview

谢谢

回答

1

试试这个:

dgvPresets.Rows(10).Cells(1).ValueType = GetType(Double) 
dgvPresets.Rows(10).Cells(1).Style.Format = "N2" 
1

可以韩德尔DataGridView1_CellFormatting

Private Sub DataGridView1_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles DataGridView1.CellFormatting 
     If e.ColumnIndex = 1 AndAlso IsNumeric(e.Value) Then 

      e.Value = Format(e.Value, "#,##0.00") 
     End If 
    End Sub 
相关问题