demoniumz
asked on
Textbox format vb 2005
Hello i have a textbox that needed to display the total .Now the total is apear like (example) 110
i want to format it to be like $110.00 can someone give me the code/I
i want to format it to be like $110.00 can someone give me the code/I
You can use the following:
textBox1.Text = Strings.FormatCurrency(amo unt)
if you are on a computer where the language settings are american.
If you do not know for sure where your program will run, you can specify a culture. It becomes a bit more verbose:
textBox1.Text = amount.ToString("{0:C}", CultureInfo.CreateSpecific Culture("e n-US"))
If you want to set that culture for your whole program, it depends whether you have a web application or whether you are using a winforms application. For a web application, it should best be set globally in web.config. For a desktop application it should be set using
-- Abel --
textBox1.Text = amount.ToString("{0:C}", CultureInfo.CreateSpecific
If you want to set that culture for your whole program, it depends whether you have a web application or whether you are using a winforms application. For a web application, it should best be set globally in web.config. For a desktop application it should be set using
Thread.CurrentThread.Curre ntCulture = CultureInfo.CreateSpecific Culture("e n-US")
somewhere in the beginning of your application.-- Abel --
ASKER
with the first comand in your firtsnpost textbox1....(amount) the textbox apear like $0.00 witth these code?
Then there's nothing inside amount? You need to pass in a variable that holds the correct amount and I assumed you had such a variable. I mean it like this:
Dim amount As Decimal = 110.0D
textBox1.Text = Strings.FormatCurrency(amo unt)
textBox1.Text = Strings.FormatCurrency(amo
ASKER
i mean my freind i want to have something like this
OrdersDetailsDataGridView. Columns(5) .DefaultCe llStyle.Fo rmat = "¬0.00"
These is for datagrid view total row i want to display "¬0.00" when a new peoduct added to update the amount
OrdersDetailsDataGridView.
These is for datagrid view total row i want to display "¬0.00" when a new peoduct added to update the amount
ASKER
i mean my freind i want to have something like this
OrdersDetailsDataGridView. Columns(5) .DefaultCe llStyle.Fo rmat = "$0.00"
These is for datagrid view total row.Me want i want is for Textbox
i want to display "$0.00" when a new product added to update the amount not remain $0.00
understand what i mean?
OrdersDetailsDataGridView.
These is for datagrid view total row.Me want i want is for Textbox
i want to display "$0.00" when a new product added to update the amount not remain $0.00
understand what i mean?
The format string for a currency is "{0:C}", but in the case of the DefaultCellStyle.Format, you should only use the currency formatter part (I know, it is always very unclear what syntax to use where in .NET when it comes to formatting):
OrdersDetailsDataGridView. Columns(5) .DefaultCe llStyle.Fo rmat = "c"
-- Abel --ASKER
problem why ehen in the form lets say there is a product Quantity 8 and amount 1.66 give 8 euro
the real result is 8.30 euro why that ?
the real result is 8.30 euro why that ?
That's on another page and I have no idea, please show the code that demonstrates that problem.
ASKER
Public Class Norder
Private Sub Norder_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub OrdersBindingNavigatorSave Item_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OrdersBindingNavigatorSave Item.Click
Me.Validate()
Me.OrdersBindingSource.End Edit()
Me.OrdersTableAdapter.Upda te(Me.Nico laouDBData Set.Orders )
End Sub
Private Sub Addpr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Addpr.Click
Dim bsource As BindingSource = Me.OrdersDetailsDataGridVi ew.DataSou rce
Dim ds As DataSet = DirectCast(bsource.DataSou rce, DataSet)
Dim orderdetailstable As New DataTable
Dim dr As DataRow = ds.Tables("OrdersDetails") .NewRow
dr("OrderID") = OrderIDTextBox.Text
dr("ProductID") = Productidcombobox.Selected Value
dr("UnitPrice") = Unitpricetextbox.Text
dr("Quantity") = QuantityTextBox.Text
dr("productname") = ProductNameTextBox.Text
dr("Discount") = 0
dr("Total records") = 0
dr("Total") = Convert.ToDecimal(Unitpric etextbox.T ext.ToStri ng()) * Convert.ToDecimal(Quantity TextBox.Te xt.ToStrin g())
ds.Tables("OrdersDetails") .Rows.Add( dr)
TotalSum()
End Sub
Private Sub OrdersDetailsBindingSource BindingNav igatorSave Item_Click (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OrdersBindingNavigatorSave Item.Click
Me.Validate()
Me.OrdersDetailsBindingSou rce.EndEdi t()
Me.OrdersDetailsTableAdapt er.Update( Me.Nicolao uDBDataSet .OrdersDet ails)
End Sub
Private Sub clearbu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles delbut.Click
OrdersDetailsDataGridView. Rows.Remov e(OrdersDe tailsDataG ridView.Cu rrentRow)
TotalSum()
End Sub
Private Sub TotalSum()
Dim sum As Decimal = 0
For Each row As DataGridViewRow In OrdersDetailsDataGridView. Rows
row.Cells(5).Value = row.Cells(3).Value * row.Cells(4).Value
sum += row.Cells(5).Value
Next
Me.TextBox1.Text = sum
Me.TextBox1.Text = sum.ToString("¬0.00")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clearbut.Click
Me.NicolaouDBDataSet.Order sDetails.C lear()
End Sub
Private Sub movenext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles movenext.Click
OrdersBindingSource.MoveNe xt()
End Sub
Private Sub moveprevius_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles moveprevius.Click
OrdersBindingSource.MovePr evious()
End Sub
Private Sub movelast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles movelast.Click
OrdersBindingSource.MoveLa st()
End Sub
Private Sub movefirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles movefirst.Click
OrdersBindingSource.MoveFi rst()
End Sub
Private Sub addrec_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addrec.Click
Me.NicolaouDBDataSet.Order sDetails.C lear()
TextBox1.Text = String.Empty
OrdersBindingSource.AddNew ()
End Sub
Private Sub delrec_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles delrec.Click
OrdersBindingSource.Remove Current()
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub ToolStripButton1_Click(ByV al sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
'TODO: This line of code loads data into the 'NicolaouDBDataSet.Supplie rs' table. You can move, or remove it, as needed.
Me.SuppliersTableAdapter.F ill(Me.Nic olaouDBDat aSet.Suppl iers)
'TODO: This line of code loads data into the 'NicolaouDBDataSet.Product s' table. You can move, or remove it, as needed.
Me.ProductsTableAdapter.Fi ll(Me.Nico laouDBData Set.Produc ts)
'TODO: This line of code loads data into the 'NicolaouDBDataSet.OrdersD etails' table. You can move, or remove it, as needed.
Me.OrdersDetailsTableAdapt er.Fill(Me .NicolaouD BDataSet.O rdersDetai ls)
'TODO: This line of code loads data into the 'NicolaouDBDataSet.Supplie rs' table. You can move, or remove it, as needed.
Me.SuppliersTableAdapter.F ill(Me.Nic olaouDBDat aSet.Suppl iers)
'TODO: This line of code loads data into the 'NicolaouDBDataSet.Orders' table. You can move, or remove it, as needed.
Me.OrdersTableAdapter.Fill (Me.Nicola ouDBDataSe t.Orders)
OrdersDetailsDataGridView. Columns(5) .DefaultCe llStyle.Fo rmat = "¬0.00"
TotalSum()
End Sub
Private Sub email_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles email.Click
Nemail.Show()
End Sub
Private Sub callendar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles callendar.Click
Ncalendar.Show()
End Sub
Private Sub touch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles touch.Click
Process.Start("osk.exe")
End Sub
Private Sub infos_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles infos.Click
NicolaouInfos.Show()
End Sub
End Class
Private Sub Norder_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub OrdersBindingNavigatorSave
Me.Validate()
Me.OrdersBindingSource.End
Me.OrdersTableAdapter.Upda
End Sub
Private Sub Addpr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Addpr.Click
Dim bsource As BindingSource = Me.OrdersDetailsDataGridVi
Dim ds As DataSet = DirectCast(bsource.DataSou
Dim orderdetailstable As New DataTable
Dim dr As DataRow = ds.Tables("OrdersDetails")
dr("OrderID") = OrderIDTextBox.Text
dr("ProductID") = Productidcombobox.Selected
dr("UnitPrice") = Unitpricetextbox.Text
dr("Quantity") = QuantityTextBox.Text
dr("productname") = ProductNameTextBox.Text
dr("Discount") = 0
dr("Total records") = 0
dr("Total") = Convert.ToDecimal(Unitpric
ds.Tables("OrdersDetails")
TotalSum()
End Sub
Private Sub OrdersDetailsBindingSource
Me.Validate()
Me.OrdersDetailsBindingSou
Me.OrdersDetailsTableAdapt
End Sub
Private Sub clearbu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles delbut.Click
OrdersDetailsDataGridView.
TotalSum()
End Sub
Private Sub TotalSum()
Dim sum As Decimal = 0
For Each row As DataGridViewRow In OrdersDetailsDataGridView.
row.Cells(5).Value = row.Cells(3).Value * row.Cells(4).Value
sum += row.Cells(5).Value
Next
Me.TextBox1.Text = sum
Me.TextBox1.Text = sum.ToString("¬0.00")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clearbut.Click
Me.NicolaouDBDataSet.Order
End Sub
Private Sub movenext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles movenext.Click
OrdersBindingSource.MoveNe
End Sub
Private Sub moveprevius_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles moveprevius.Click
OrdersBindingSource.MovePr
End Sub
Private Sub movelast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles movelast.Click
OrdersBindingSource.MoveLa
End Sub
Private Sub movefirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles movefirst.Click
OrdersBindingSource.MoveFi
End Sub
Private Sub addrec_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addrec.Click
Me.NicolaouDBDataSet.Order
TextBox1.Text = String.Empty
OrdersBindingSource.AddNew
End Sub
Private Sub delrec_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles delrec.Click
OrdersBindingSource.Remove
End Sub
Private Sub TextBox1_TextChanged(ByVal
End Sub
Private Sub ToolStripButton1_Click(ByV
'TODO: This line of code loads data into the 'NicolaouDBDataSet.Supplie
Me.SuppliersTableAdapter.F
'TODO: This line of code loads data into the 'NicolaouDBDataSet.Product
Me.ProductsTableAdapter.Fi
'TODO: This line of code loads data into the 'NicolaouDBDataSet.OrdersD
Me.OrdersDetailsTableAdapt
'TODO: This line of code loads data into the 'NicolaouDBDataSet.Supplie
Me.SuppliersTableAdapter.F
'TODO: This line of code loads data into the 'NicolaouDBDataSet.Orders'
Me.OrdersTableAdapter.Fill
OrdersDetailsDataGridView.
TotalSum()
End Sub
Private Sub email_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles email.Click
Nemail.Show()
End Sub
Private Sub callendar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles callendar.Click
Ncalendar.Show()
End Sub
Private Sub touch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles touch.Click
Process.Start("osk.exe")
End Sub
Private Sub infos_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles infos.Click
NicolaouInfos.Show()
End Sub
End Class
ASKER
Private Sub TotalSum()
Dim sum As Decimal = 0
For Each row As DataGridViewRow In OrdersDetailsDataGridView. Rows
row.Cells(5).Value = row.Cells(3).Value * row.Cells(4).Value
sum += row.Cells(5).Value
Next
Me.TextBox1.Text = sum
Me.TextBox1.Text = sum.ToString("$0.00") The total column (textbox)
End Sub
OrdersDetailsDataGridView. Columns(5) .DefaultCe llStyle.Fo rmat = "$0.00"
the total of row
Dim sum As Decimal = 0
For Each row As DataGridViewRow In OrdersDetailsDataGridView.
row.Cells(5).Value = row.Cells(3).Value * row.Cells(4).Value
sum += row.Cells(5).Value
Next
Me.TextBox1.Text = sum
Me.TextBox1.Text = sum.ToString("$0.00") The total column (textbox)
End Sub
OrdersDetailsDataGridView.
the total of row
ASKER
so?
ASKER
abel:can u help
Sorry, I went to bed... (it was midnight on this side of earth) Remember, we're all volunteers, and we do this in our sparse free time, so pushing is not going to help.
I see from the code above that you didn't apply the suggestions I gave you. You write, last line above, the following:
You seem to suggest that your total is not correct. I cannot judge that, because I have not idea what's in the columns that you are calculating. But it is a common mistake that people think that Cell(1) is the very first cell. It isn't, the first cell is Cell(0). Same accounts for Column and Row. Might that be where your problem is?
If I'm wrong here, please post your code again (this time in the code snippet section please!) and comment on what you expect where and what the current wrong values are. You can find that by stepping through your code with F10 after you hit a breakpoint.
-- Abel --
I see from the code above that you didn't apply the suggestions I gave you. You write, last line above, the following:
OrdersDetailsDataGridView. Columns(5) .DefaultCe llStyle.Fo rmat = "$0.00"
but you should make it this:
OrdersDetailsDataGridView. Columns(5) .DefaultCe llStyle.Fo rmat = "$0.00"
You have other places where you try sum.ToString("¬0.00"), try instead, sum.ToString("{0:C"}. Also, as suggested earlier.You seem to suggest that your total is not correct. I cannot judge that, because I have not idea what's in the columns that you are calculating. But it is a common mistake that people think that Cell(1) is the very first cell. It isn't, the first cell is Cell(0). Same accounts for Column and Row. Might that be where your problem is?
If I'm wrong here, please post your code again (this time in the code snippet section please!) and comment on what you expect where and what the current wrong values are. You can find that by stepping through your code with F10 after you hit a breakpoint.
-- Abel --
ASKER
Your sugested before is tried giving the same result
I see that I made a copy and paste error in that last comment. The bold line should have been
OrdersDetailsDataGridView. Columns(5) .DefaultCe llStyle.Fo rmat = "c"
You are not really giving me the information I need to help you with this issue. Let's do this step by step. Please try the following and give me the results from the debug window:
Dim dblTest As Double = 12.34Debug.WriteLine("test double as amount: " & dblTest.ToString("c"))
ASKER
<System.Diagnostics.Debugg erNonUserC odeAttribu te(), _
System.ComponentModel.Brow sableAttri bute(true) , _
System.ComponentModel.Desi gnerSerial izationVis ibilityAtt ribute(Sys tem.Compon entModel.D esignerSer ialization Visibility .Visible)> _
Public Overrides Property SchemaSerializationMode() As System.Data.SchemaSerializ ationMode
Get
Return Me._schemaSerializationMod e
End Get
Set
Me._schemaSerializationMod e = value
End Set
End Property
i get these with a yellow thing in front
System.ComponentModel.Brow
System.ComponentModel.Desi
Public Overrides Property SchemaSerializationMode() As System.Data.SchemaSerializ
Get
Return Me._schemaSerializationMod
End Get
Set
Me._schemaSerializationMod
End Set
End Property
i get these with a yellow thing in front
Now you got me totally lost. This is about a serialization mode for a schema, I don't see what this has to do with a textbox. And I don't see anything yellow (use a screenshot and upload it if you want to show something visually). Can you please elaborate on what you are after? And can you please answer my last comment after trying that out?
ASKER
i am totaly confused me 2:)
here is my database can u check if the total column in table order details is in corect format
NicolaouDB.mdb
here is my database can u check if the total column in table order details is in corect format
NicolaouDB.mdb
I don't see what this has to do with your original request on how to format a format a textbox. I'm not an Access guru. But the Total column is clearly of some Integer type, it cannot accept decimals. Why are you asking? What is the relation?
If that is the field that you want to display in a textbox, the result will be something like $11.00, where the "00" is always "00".
If that is the field that you want to display in a textbox, the result will be something like $11.00, where the "00" is always "00".
ASKER
ok iask you sonmething now in order to not be alwayss 00 what i must put?To give me the corect cents
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ok i try
ASKER
thnks abel and cool down men:)