Link to home
Start Free TrialLog in
Avatar of itsos
itsos

asked on

How to format a textbox on a windows form

How can I format a textbox on a windows form and datagrid to display a number with the following format

500,000

I'm connecting to an Access database and the field is displayed correctly in the database.  However on my windows form and datagrid it looks like this:

500000

Hope somebody can help me.

Kind regards,
Itsos
ASKER CERTIFIED SOLUTION
Avatar of bhnv9
bhnv9

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of itsos
itsos

ASKER

Thank you bhnv9 for your quick reply.  Your suggestion doesn't seem to work for me.  This is what I have done:

Private Sub InitializeTextBox()
  Format(Text1.Text, "###,###,###")
End Sub

Private Sub frmCustomers_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  InitializeTextBox()
End Sub

Any suggestions??

Kind regards,
itsos
Format(Text1.Text, "###,###,###") changes the text already in the textbox.
If you want that the textbox will have a data format use the design property "dataformat" and custemize it to have a 1000 separator
Avatar of itsos

ASKER

Hi again,

Thanks for your reply.

Format(Text1.Text, "###,###,###") does not change the text that is already in the textbox.  The value is still shown as 500000.

Also there is no "dataformat" property in Visual Basic .NET.  Do you know the equivalent in .NET?

Kind regards,
itsos

Sorry, don't know .net. Didn't realize that was what you were using
Did you check your language dependant settings?
I mean the thousand and decimal separators.
Avatar of itsos

ASKER

I have solved my problem with the following code:

Private Sub Textbox1_Validated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Textbox1.Validated

Textbox1.Text = Format(Val(Textbox1.Text), "###,###,###,###")

End Sub

Thanks for your input...

Kind regards,
itsos
Avatar of itsos

ASKER

Close enough...

Cheers.