|
Hi all
I have to display data in text box with currency format(comma seperated) with decimal round to 2
I am using Winforms 2005 . similar like 32,344,343,432.50 when the user types 3234434343250
using which control i can achieve this textbox or masked textbox
Any help
Thanks in advance
DAM | | damu maddy Saturday, February 21, 2009 12:21 AM |
Hi damu maddy,
I think you need to create an inherited TextBox. There is no such control can fully meet your need. Here is the code.
| publicclassMyTextBox:TextBox |
| { |
| publicMyTextBox() |
| { |
| |
| } |
|
| protectedoverridevoidOnValidating(CancelEventArgse) |
| { |
| base.OnValidating(e); |
| stringresult=this.Text; |
| if(this.Text.Contains('.')) |
| { |
| for(inti=this.Text.IndexOf('.');i>=0;i--) |
| { |
| if((this.Text.IndexOf('.')-i)%3==0&&(this.Text.IndexOf('.')-i)!=0&&i!=0) |
| { |
| result=result.Insert(i,","); |
| } |
| } |
| } |
| else |
| { |
| for(inti=this.Text.Length;i>=0;i--) |
| { |
| if((this.Text.Length-i)%3==0&&(this.Text.Length-i)!=0&&i!=0) |
| { |
| result=result.Insert(i,","); |
| } |
| } |
| } |
| this.Text=result; |
| } |
|
| protectedoverridevoidOnGotFocus(EventArgse) |
| { |
| base.OnGotFocus(e); |
| this.Text=this.Text.Replace(",",""); |
| } |
| } |
I think this can help you solve the problem.
If you have any question, please feel free to tell me.
Sincerely, Kira Qian
Please mark the replies as answers if they help and unmark if they don't. - Marked As Answer bydamu maddy Wednesday, March 25, 2009 7:58 PM
- Unmarked As Answer bydamu maddy Wednesday, March 25, 2009 7:58 PM
- Marked As Answer byKira QianMSFT, ModeratorFriday, February 27, 2009 9:31 AM
-
| | Kira Qian Tuesday, February 24, 2009 4:10 AM | Go to properties DataBindings (Advanced) and select numeric or currency and the format you wish. | | oiftimus Saturday, February 21, 2009 8:18 AM |
the user manualy enter values in textbox and it is not binded to DB
Regards, DAM
| | damu maddy Monday, February 23, 2009 3:28 PM |
Hi damu maddy,
I think you need to create an inherited TextBox. There is no such control can fully meet your need. Here is the code.
| publicclassMyTextBox:TextBox |
| { |
| publicMyTextBox() |
| { |
| |
| } |
|
| protectedoverridevoidOnValidating(CancelEventArgse) |
| { |
| base.OnValidating(e); |
| stringresult=this.Text; |
| if(this.Text.Contains('.')) |
| { |
| for(inti=this.Text.IndexOf('.');i>=0;i--) |
| { |
| if((this.Text.IndexOf('.')-i)%3==0&&(this.Text.IndexOf('.')-i)!=0&&i!=0) |
| { |
| result=result.Insert(i,","); |
| } |
| } |
| } |
| else |
| { |
| for(inti=this.Text.Length;i>=0;i--) |
| { |
| if((this.Text.Length-i)%3==0&&(this.Text.Length-i)!=0&&i!=0) |
| { |
| result=result.Insert(i,","); |
| } |
| } |
| } |
| this.Text=result; |
| } |
|
| protectedoverridevoidOnGotFocus(EventArgse) |
| { |
| base.OnGotFocus(e); |
| this.Text=this.Text.Replace(",",""); |
| } |
| } |
I think this can help you solve the problem.
If you have any question, please feel free to tell me.
Sincerely, Kira Qian
Please mark the replies as answers if they help and unmark if they don't. - Marked As Answer bydamu maddy Wednesday, March 25, 2009 7:58 PM
- Unmarked As Answer bydamu maddy Wednesday, March 25, 2009 7:58 PM
- Marked As Answer byKira QianMSFT, ModeratorFriday, February 27, 2009 9:31 AM
-
| | Kira Qian Tuesday, February 24, 2009 4:10 AM |
|