I am using MS SQL Server and Visual Basic.
I want to combine a calculated column and another column to add units to the calculation. (for example "200 m2")
DgwNewLayout.Columns(5).DefaultCellStyle.Format = "0.00 " & "'" & DgwNewLayout.CurrentRow.Cells(9).Value & "'"
This code does that but only for first entered unit? How can I do this for each column?
You could use CellFormatting
event.
Private WithEvents DgwNewLayout As DataGridView
Private Sub DgwNewLayout_CellFormatting(sender As Object,
e As DataGridViewCellFormattingEventArgs
) Handles DgwNewLayout.CellFormatting
If e.ColumnIndex = 5 Then
e.Value = CDbl(e.Value).ToString("0.00") &
" " & CStr(DgwNewLayout.Rows(e.RowIndex).Cells(9).Value)
e.FormattingApplied = True
End If
End Sub
As Dom Sinclair says, this could have poor performance.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.