Question

I am working in C++ .net. I have a custom control that shows the contents of a dataBase with a bindingsource in between. I use labels in the control to bind the text property to the data in the dataset through a bindingsource with the following code:

mycontrol->Controls[i]->DataBindings->Add((gcnew System::Windows::Forms::Binding(L"Text", 
this->bindingSourceRelRev_Data, mycolumn,true, System::Windows::Forms::DataSourceUpdateMode::OnValidation,
nullptr, L"t")));

Please, note that the code is an excerpt of a loop that iterates on all the controls, therefore the control[i], which would be the label control, and the variable mycolumn, which would be the column of the dataset to be binded to. It works fine apart of an unwanted behaviour that I haven't yet found the way to change. The sofware runs in different parts of the world but the records must be in local time. The database stores the time in localtime as a DateTime value but the dataBinding interprets it as UTC and shows the time in the label with the timezone difference applied. For example, if the data is 24/06/2012 16:40, it will show 24/06/2012 22:40 in a 4 hours difference time zone. I need it to show just the value as it was stored, without changes.

I can think of different ways to go arround, but non elegant: -capture the text update event of the label and un-do the change... -Store the date as String in the DB... -fill manually the labels... -...

If I bind without formating, it will not change the value, but then I have the raw datetime string on the label...

Please, any magic I am missing in the binding so that it will not assume it has to change the time zone?

Thank you very much in advance! Adan

Was it helpful?

Solution

well, it seems that the problem was not actually on the binding but in the dataset itself. The columns' property DateTimeMode was set as undefinedlocal and this was serializing the dataimput and converting it to the local time of the machine viewing the data. Just changed the property to undefined and it works now as I wanted, just taking the date from the data unmodified.

I was confused by the documentation on the format provider for DateTime, which states that it serializes the date. Perhaps I missunderstood it... It actually doesn't.

Thank you very much anyway!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top