views:

978

answers:

1

Hi,

I haev an object with a DateTime property. I want to map the time to a textbox (thus want the user enter the time, it's directly reverberated to my property).

However I just want to display the time. How can I say this (ie the format should be something like hh:mm to be correct).

Less specifcly how can I format the text "sent" to the object and the other way too ?

Thx

+1  A: 

You can specify "HH:mm" as the binding's FormatString

If you need more complex formatting than what a format string can provide, you can handle the Format event of the binding, which enables you to provide your own formatting logic

Thomas Levesque
Sounds that it is what I'm looking for however the whole datetime is displayed (daysn months etc..). I put the folowwing code : textBoxHorodatage.DataBindings.Add("Text", _customObject, "HoroDate"); textBoxHorodatage.DataBindings[0].FormatString = "hh:mm";
Toto
Bis - is there a way to retrieve the binding object in a better way than [0] ?
Toto
I should had : textBoxHorodatage.DataBindings[0].FormattingEnabled = true;
Toto
Ah oui, j'avais oublié FormattingEnabled ;). Une meilleure solution que [0] : textBoxHorodatage.DataBindings["Text"]
Thomas Levesque
Merci bien. Dernière question, quand on tape un format erroné, le control n'est, bien sur, pas validé. Donc la text box garde le focus, est ce qu'il y a un event du genre : ValidateFailed or BindingFailed etc ?
Toto
Il y a un évènement BindingComplete, avec des paramètres qui peuvent t'indiquer s'il y a eu une erreur
Thomas Levesque
Ok c'est encore bien ce que je cherchais, dsl mes yeux l'ont raté.
Toto