Dim myCurrency as Decimal
myCurrency = Decimal.Parse(lvitem.Subitems(2).Text)
lvitem.Subitems(2).text = String.Format("{0:n2}", myCurrency)
Dim myCurrency as Decimal = Ctype(textBox1.text, Decimal)
textBox1.text = String.Format("{0:n2}", myCurrency)
Public Class myCurrency
Public Sub formating(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs)
If TypeOf sender Is TextBox Then
Dim txt As TextBox = DirectCast(sender, TextBox)
txt.Text = String.Format("{0:n2}", CType(txt.Text, Decimal))
End If
End Sub
Public Sub AddFormating(ByRef tb As TextBox)
AddHandler tb.Validating, AddressOf formating
End Sub
Public Sub RemoveFormating(ByRef tb As TextBox)
RemoveHandler tb.Validating, AddressOf formating
End Sub
End Class
Dim myCurrency as myCurrency = New myCurrency
myCurrency.AddFormating(TextBox1)
Private Sub GridColumns()
Dim TSPaid As New DataGridTableStyle
TSPaid.MappingName = "Payments"
TSPaid.AllowSorting = True
Dim oDate As New DataGridTextBoxColumn
oDate.MappingName = "Date"
oDate.HeaderText = "DATE"
oDate.Width = 65
TSPaid.GridColumnStyles.Add(oDate)
.......More Columns Code..........
[b]I need to apply the currency format to this column:[/b]
[i]Dim oValue As New DataGridTextBoxColumn[/i]
[i] oValue.MappingName = "Value"[/i]
[i] oValue.HeaderText = "VALUE"[/i]
[i] oValue.Width = 60[/i]
[i] [b]oValue.Format........?[/b][/i]
[i] TSPaid.GridColumnStyles.Add(oValue)[/i]
[i] myGrid.TableStyles.Add(TSPaid)[/i]
End Sub
oValue.Format("{0:n2}", Convert.ToDecimal(Container.DataItem("ColumnName")))
Dim oValue As New DataGridTextBoxColumn
Dim Res As Integer = oValue.MappingName = "Value"
Dim vFormat = String.Format("{0:n2}", Res)
oValue.MappingName = "Value"
oValue.HeaderText = "VALUE"
oValue.Width = 60
oValue.Format=vFormat
TSClientes.GridColumnStyles.Add(oValue)
jmcilhinney said:I think the DataGrid is too much like a raw database.
Thanks Paszt. You are the first recipient of Rep from me for this post.Paszt said:For You Information: MSDN has a great article that shows how to create a databound listview here: Creating a Data Bound ListView Control
This article really helped me to understand databinding and it's also a very useful control.