locked
Bindingsource Binding multi control to same property (catch Changes) RRS feed

  • Question

  • Hello

    I have form bindingsource with datasource is datatable (using dataset or not is the same)

    Let say I have a table ITEM with field ITEM_NAME

    I have  3 tabpage in my form

    in each pagetab a textbox (plus other controls, combo other textbox, check box etc)

    each text box is bound to same property, ITEM.NAME using bindingsource

    My question

    How to capture if one of the textbox changes the other textbox bounded to the same bindingsource also changes without coding in the textChanged() of each textbox

    I did my tests, I only managed to achieve that by using BindingComplete Event

        Private Sub MyBindingSource_BindingComplete(sender As Object, e As BindingCompleteEventArgs) Handles MyBindingSource.BindingComplete
                MyBindingSource.EndEdit        
        End Sub

    but this approch will prevent me from changing other controls. If I change another control value and I save changes using the tableadapter they will not be saved because i use Endedit() where its known that you should code Endedit() then save, not using endedit then change values then save (I know that)

    So how to make other controls changes if they share the same property in bindingsource() ?

    Thanks



    .Net Blog VFP Blog


    Wednesday, October 28, 2020 2:59 PM

All replies

  • Hello,

    Look at the DataTable events to determine what changed but will not tell you exactly which control (TextBox) the change was in, that should not matter generally speaking. You can also peek at the values prior and proposed (current value) in many of the events.

    EDIT: The following code sample I pulled from a very old code sample I did that may help with the above.

    Screenshot for a edit


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange


    Wednesday, October 28, 2020 3:19 PM
  • Hi Karen

    Interesting information. But I need the event to work on bindingsource


    I found a silly way to my problem

    I don't know the side effect if I implemented in class later

    Your advice is appreciated on my solution

    Private Sub bs_item_BindingComplete(sender As Object, e As BindingCompleteEventArgs) Handles bs_item.BindingComplete
            
            bs_item.EndEdit        
            Dim dt As DataTable = bs_item.DataSource
            For i = 0 To dt.Columns.Count - 1
                bs_item.Current(dt.Columns(i)) = bs_item.Current(dt.Columns(i))
            Next
            
    End Sub

    After EndEdit() I re-enter the value equal itself, so the row flag will be changed to Modified, so later on when I issue ta_ITEM.Update(bs_item.datasource) the later changes on other control will occur

    What do you think?


    .Net Blog VFP Blog

    Wednesday, October 28, 2020 9:05 PM
  • Hi Karen

    Interesting information. But I need the event to work on bindingsource


    I found a silly way to my problem

    I don't know the side effect if I implemented in class later

    Your advice is appreciated on my solution

    Private Sub bs_item_BindingComplete(sender As Object, e As BindingCompleteEventArgs) Handles bs_item.BindingComplete
            
            bs_item.EndEdit        
            Dim dt As DataTable = bs_item.DataSource
            For i = 0 To dt.Columns.Count - 1
                bs_item.Current(dt.Columns(i)) = bs_item.Current(dt.Columns(i))
            Next
            
    End Sub

    After EndEdit() I re-enter the value equal itself, so the row flag will be changed to Modified, so later on when I issue ta_ITEM.Update(bs_item.datasource) the later changes on other control will occur

    What do you think?


    .Net Blog VFP Blog

    What I provided WILL work with a BindingSource, simply set the subscribe to the events then set the BindingSource.DataSource to the DataTable and it simply works.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Wednesday, October 28, 2020 9:59 PM