Results 1 to 8 of 8

Thread: DateTimePicker which has databoundingsource doesn't change while moving through ...

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2014
    Posts
    274

    DateTimePicker which has databoundingsource doesn't change while moving through ...

    I have PurchaseOrderDateTimePicker on my form which works with databoundingsource. But there is a problem since the date is always same while moving through the records. It shows the date even there is no date in that record.

    How to resolve it?. Please help.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,467

    Re: DateTimePicker which has databoundingsource doesn't change while moving through .

    Firstly, there's no such thing as a databoundingsource. Do you mean a BindingSource?

    As for the issue, the DateTimePicker control doesn't support binding to nullable data. That's because the Value property that you're binding to is type DateTime and that must always have a value. You will need to either handle that column and control manually or else create your own derived control that adds a new property to bind to and plays with the Checked and CustomFormat properties to display an empty control when the bound data is null.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2014
    Posts
    274

    Re: DateTimePicker which has databoundingsource doesn't change while moving through .

    Thanks for the reply. Yes it is a "Binding Source". To resolve this problem, I want to remove the DateTimePicker and instead of that to use txtUpdatedOn.Text for the date field, how to save this fields along with the other texboxes which are connected by BindingSource. How can I modify the existing code which is working fine for textboxes which are using BindingSource:

    Code:
    Private Sub TblEMPLOYEESBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles TblEMPLOYEESBindingNavigatorSaveItem.Click
            Me.Validate()
            Me.TblEMPLOYEESBindingSource.EndEdit()
            Me.TableAdapterManager.UpdateAll(Me.AAMCOEmployeesDataSet)
    -----Here I need to add code for txtUpdatedOn.Text to be saved along with other textboxes
    End Sub
    Please help me with the code.

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,467

    Re: DateTimePicker which has databoundingsource doesn't change while moving through .

    Quote Originally Posted by VS2013 View Post
    Thanks for the reply. Yes it is a "Binding Source". To resolve this problem, I want to remove the DateTimePicker and instead of that to use txtUpdatedOn.Text for the date field, how to save this fields along with the other texboxes which are connected by BindingSource. How can I modify the existing code which is working fine for textboxes which are using BindingSource:

    Code:
    Private Sub TblEMPLOYEESBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles TblEMPLOYEESBindingNavigatorSaveItem.Click
            Me.Validate()
            Me.TblEMPLOYEESBindingSource.EndEdit()
            Me.TableAdapterManager.UpdateAll(Me.AAMCOEmployeesDataSet)
    -----Here I need to add code for txtUpdatedOn.Text to be saved along with other textboxes
    End Sub
    Please help me with the code.
    If you're binding your Date column to a TextBox instead of a DateTimePicker then you don't need to change any code other than the line that binds that column. Everything else is exactly the same.

    That said, you'll need to add some validation for the that field because, unlike a DateTimePicker, a TextBox won't do that for you.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2014
    Posts
    274

    Re: DateTimePicker which has databoundingsource doesn't change while moving through .

    Thanks once again. How it can be done? Any example, plz.

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,467

    Re: DateTimePicker which has databoundingsource doesn't change while moving through .

    Quote Originally Posted by VS2013 View Post
    Thanks once again. How it can be done? Any example, plz.
    The binding would be done the same way you're already doing it. As for the validation, handle the Validating event of the control and then, in the simplest form, do something like this:
    Code:
    e.Cancel = myTextBox.Text <> "" AndAlso Not Date.TryParse(myTextBox.Text, Nothing)
    If the control contents is not valid then e.Cancel is set to True and the control will refuse to lose focus. You'll probably want to display a message to the user in that case too.

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Dec 2014
    Posts
    274

    Re: DateTimePicker which has databoundingsource doesn't change while moving through .

    After binding some TextBoxes which holds Date, My Form updates the data saved in debugging mode but when I close and open the Project the values are not updated.

    Code:

    Code:
    Private Sub TblEMPLOYEESBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles TblEMPLOYEESBindingNavigatorSaveItem.Click
            Me.Validate()
            Me.TblEMPLOYEESBindingSource.EndEdit()
            Me.TableAdapterManager.UpdateAll(Me.AAMCOEmployeesDataSet)
    
        End Sub

  8. #8
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    105,467

    Re: DateTimePicker which has databoundingsource doesn't change while moving through .

    Quote Originally Posted by VS2013 View Post
    After binding some TextBoxes which holds Date, My Form updates the data saved in debugging mode but when I close and open the Project the values are not updated.

    Code:

    Code:
    Private Sub TblEMPLOYEESBindingNavigatorSaveItem_Click(sender As Object, e As EventArgs) Handles TblEMPLOYEESBindingNavigatorSaveItem.Click
            Me.Validate()
            Me.TblEMPLOYEESBindingSource.EndEdit()
            Me.TableAdapterManager.UpdateAll(Me.AAMCOEmployeesDataSet)
    
        End Sub
    That's likely to be how you've configured the database in your project. To confirm whether or not the data is being saved, test the value returned by UpdateAll. If that's not zero then data is being saved. To learn how to ensure that that saved data is retained, follow the first link in my signature below.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width