DarwinIcesurfer
DarwinIcesurfer

Reputation: 1133

C# Windows form text box format with data binding

I have a windows form with a text box: txtMyText.

txtMyText.Text is Bound to a data source: long lMyLongValue.

On the form I would like the value to display as a six digit value with leading zeros. Example 000123.

How can this be accomplished?

Upvotes: 1

Views: 2972

Answers (2)

Tigran
Tigran

Reputation: 62286

I believe Binding.Format event, can be pretty suitable for your needs, if not, you can bind it not to long property, but to string property and handle conversion from long -> srtring and vice versa "by hand".

for convert it into formatted string use pretty simple example:

    long l  =13;
    string sformat = l.ToString("000000"); // 000013

Regards.

Upvotes: 2

baraban
baraban

Reputation: 465

Yes, follow link How to: Pad a Number with Leading Zeros

Upvotes: 0

Related Questions