|
I have a VB 2008 application with multiple DataPicker fields. The data is binded to SQL database. On the form load I set the checkBox for each date to false if there is no date in the field. Noticed that if I make changes to some dates for record 1 in the table, save it and scroll to the next record- Isee the date that I just changed for record 1 - also on records 2 and 3. Why is it happening? I don't have that problem if I use text fields to display the dates. Is there some steps that I'm missing? I had encountered the same problem with different project and just switched to text boxes. With this new project - thought I'd give it another try - may be there is a simple way to fix it. Thanks! |
| Alla2552 Monday, November 23, 2009 9:38 PM |
Wanted to add that I have the same problem with CheckBox as well. I checked it for 1 record, choose next one and it's showing it checked from prior record! What is going on??? |
| Alla2552 Tuesday, November 24, 2009 9:58 PM |
|
| Malange Thursday, November 26, 2009 7:33 PM |
Thank you. I had checked the links. The first one didn't have any information on similar situations. In google link found a similar case where it was suggested to do a binding manually (except the situation wasn't resolved as well..) When I did that - I got an error that binding already exists (the one that was auto-created by designer). Should I try to remove default binding and replace it with manual binding, then run it on scrolling event and load event? Thanks, Alla |
| Alla2552 Monday, November 30, 2009 3:40 PM |
When it is about the checkbox and the dateTimePicker, the problem is almost forever the same, people are binding to the textbox while they have to bind to the value.
I can assure you thatyou are not the first one who binds a datetime databaseproperty to a Microsoft datetimepicker.
With a little bit more information what you are doing instead of what you think that happens, we can probably much easier help you.
Success Cor |
| Cor Ligthert Monday, November 30, 2009 5:34 PM |
The binding for datepicker is set to value, not text. So that's not it - still displays incorrect values when scrolling to next record (if value for other person is NULL). Any other suggestions? |
| Alla2552 Monday, November 30, 2009 5:43 PM |
I think the best way to handle this is to manually bind datetimepicker in code(detatch from designer) Eg.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'JewelCITDataSet.TEMP3' table. You can move, or remove it, as needed.
Me.TEMP3TableAdapter.Fill(Me.MyDataSet.TEMP3)
Dim dtpbind = New System.Windows.Forms.Binding("Value", Me.TEMP3BindingSource, "DOB", True) ' Dob is datetime field
AddHandler dtpbind.Format, AddressOf DTP_Format
AddHandler dtpbind.Parse, AddressOf DTP_Parse
Me.DateTimePicker1.DataBindings.Add(dtpbind)
End Sub
Private Sub DTP_Format(ByVal s As Object, ByVal e As ConvertEventArgs)
If e.Value Is DBNull.Value OrElse e.Value Is Nothing Then
DateTimePicker1.Checked = False
e.Value = DateTimePicker1.Value
Else
DateTimePicker1.Checked = True
End If
End Sub
Private Sub DTP_Parse(ByVal s As Object, ByVal e As ConvertEventArgs)
If Not DateTimePicker1.Checked Then
e.Value = DBNull.Value
End If
End Sub
Arjun Paudel |
| Arjun Paudel Monday, November 30, 2009 7:15 PM |
Thank you, Arjun. I tried it and it does work better. Couple of downsides - I have more than 50 date fields. That would mean code for each field... Of course I could add DateTimePicker name as a parameter to the last 2 subs - that would eliminate hundreds of sub(s). The other downside - it still shows the date from the prior record - but it's inactive - greyed out and checkmark. It's not a big deal though. At least it's not showing as active date from prior record. With checkbox I figured that if I set the advanced format to "FALSE" for Null values - it displays the value from prior record during scrolling. If I don't set it - then it's showing as "Indeterminate" for the records where it has Null value. The problem with Indeterminate - user will have to press twice in the field to actually show check mark. What is the best way to avoid double clicking? I appreciate your help! |
| Alla2552 Monday, November 30, 2009 8:02 PM |
Thank you, Arjun. I tried it and it does work better. Couple of downsides - I have more than 50 date fields. That would mean code for each field... Of course I could add DateTimePicker name as a parameter to the last 2 subs - that would eliminate hundreds of sub(s). The other downside - it still shows the date from the prior record - but it's inactive - greyed out and checkmark. It's not a big deal though. At least it's not showing as active date from prior record. With checkbox I figured that if I set the advanced format to "FALSE" for Null values - it displays the value from prior record during scrolling. If I don't set it - then it's showing as "Indeterminate" for the records where it has Null value. The problem with Indeterminate - user will have to press twice in the field to actually show check mark. What is the best way to avoid double clicking? I appreciate your help!
can you propose as answered to Arjun please so we can move on...Thanks
Don't judge me, just Upgrade me. Thanks! |
| Malange Monday, November 30, 2009 8:07 PM |
I don't have a full answer yet. You can please move on - didn't think I was holding you... |
| Alla2552 Monday, November 30, 2009 8:11 PM |
If you have multiple picker then you can use same handler as following example
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dtpbind = New System.Windows.Forms.Binding("Value", Me.TEMP3BindingSource, "DOB1", True)
AddHandler dtpbind.Format, AddressOf DTP_Format
AddHandler dtpbind.Parse, AddressOf DTP_Parse
Me.DateTimePicker1.DataBindings.Add(dtpbind)
Dim dtpbind2 = New System.Windows.Forms.Binding("Value", Me.TEMP3BindingSource, "DOB2", True)
AddHandler dtpbind2.Format, AddressOf DTP_Format
AddHandler dtpbind2.Parse, AddressOf DTP_Parse
Me.DateTimePicker2.DataBindings.Add(dtpbind2)
End Sub
Private Sub DTP_Format(ByVal s As Object, ByVal e As ConvertEventArgs)
Dim dtp = CType(CType(s, Binding).Control, DateTimePicker)
If e.Value Is DBNull.Value OrElse e.Value Is Nothing Then
dtp.Checked = False
e.Value = DateTimePicker1.Value
Else
dtp.Checked = True
End If
End Sub
Private Sub DTP_Parse(ByVal s As Object, ByVal e As ConvertEventArgs)
Dim dtp = CType(CType(s, Binding).Control, DateTimePicker)
If Not dtp.Checked Then
e.Value = DBNull.Value
End If
End Sub
I did not understand what you mean by 'setadvance format to flase for null values'. If you change dtp for different value when its not checked instead of old value, it unnecessarly creates another loop since e.value changes and messes up things. As long as checkbox is uncheked, are not you safe?
Arjun Paudel |
| Arjun Paudel Tuesday, December 01, 2009 4:09 AM |
Arjun,
Are you crazy or something, the OP refused to show code and then you start creating all kind of program pieces.
And then the OP says that is better, so has crated code and not like he/she says done it only in the designer.
I would feel me a kind of servant from that OP
Success Cor |
| Cor Ligthert Tuesday, December 01, 2009 5:48 AM |
What do you mean Cor? S/he has done nothing in code, all is designer generated I suppose.
And I am just showing how value can be parsed and formatted using proper event and with multiple datetimepickers, not much more than that.
Arjun Paudel |
| Arjun Paudel Tuesday, December 01, 2009 6:30 AM |
Arjun
He/she has not given any piece of information other than telling why your code is not working and quiet exact, so I think it is just that he/she is not allowed or don't want to show code.
Success
Cor |
| Cor Ligthert Tuesday, December 01, 2009 7:10 AM |
Arjun is correct - all code was generated by VS designer - so there is nothing I can provide (binding set in properties of the field). I tested Arjun's code - which you can see above, after I removed the default binding. So that's the only code I have pertaining to DateTimePicker. About the checkbox - I'm talking about separate type of field - not the checkbox within the DateTimePicker. Sorry for the confusion. I have the same issue with checkbox fields (again - just added by designer - no code). If record 1 has checkbox checked "true", but record 2 has no value in the checkbox and scroll between 2 records - it would show the checked value from prior record. I was wondering if I should setup similar "manual" binding with codefor checkboxes as well? In VB6 I didn't have problems like that with either type of the fields - dates or checkboxes.. Thank you, Arjun, for your help! |
| Alla2552 18 hours 1 minutes ago |