CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2006
    Posts
    645

    Using single BindingNavigator with multiple data sources

    Hi,
    I have a winforms app access a database with 6 tables. Out of 6, I am showing 3 tables on three different tabs on my Form. However, I want to do it using a single binding navigator that will use / change the respective binding source dynamically, depending on the tab that is activated by the user. Any help in this regards, would be appreciated. I have separate binding source for each of the three tables.
    Thanks before hand
    Bhushan

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Using single BindingNavigator with multiple data sources

    Post some of the code that you have. (and, if it works...)
    Code:
    ' remember to use CODE TAGS
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Jun 2006
    Posts
    645

    Re: Using single BindingNavigator with multiple data sources

    Hi,
    Underneath is the code fragment, I am trying to work with...the code is self explanatory and names are contextual and relevant. For instance, as I mentioned before, database has 6 tables ...3 main course and 3 others with each one having a relationship with one of the main course tables..Considering table 1 as Tab1 and its related table to be Tab1Rel, the binding sources for each are tab1BdSrc and tab1RelBdSrc respectively and like wise for remaining tables...GetDataBO1() returns a combined dataset of Tab1 rows and related Tab1Rel rows in a single data set object....and like wise for other datasets...
    After explaining this, my problem is just bindingnavigator and bindingsource specific...i.e., even if I do not use object data sources, the concept still remain fairly similar. I just want to change the binding source of a binding navigator at runtime depending on what tab user selects...

    Code:
    Public Sub OnTab1()
        tab1BdSrc.DataSource = BLL.MyBizObj1.GetBOData1()        'Get complete data for both tables
        tab1RelBdSrc.DataSource = tab1BdSrc       'Retrieve the related rows only
        tab1RelBdSrc.DataMember = "tab1RelBdSrcobject member inside tab1BdSrc"
        If tabCommonBdNavig.BindingSource <> Nothing Then
            tabCommonBdNavig.BindingSource = Nothing
        tabCommonBdNavig.BindingSource = tab1BdSrc
    End Sub
    
    Public Sub OnTab2()
        tab2BdSrc.DataSource = BLL.MyBizObj2.GetBOData2()        'Get complete data for both tables
        tab2RelBdSrc.DataSource = tab2BdSrc       'Retrieve the related rows only
        tab2RelBdSrc.DataMember = "tab2RelBdSrcobject member inside tab2BdSrc"
        If tabCommonBdNavig.BindingSource <> Nothing Then
            tabCommonBdNavig.BindingSource = Nothing
        tabCommonBdNavig.BindingSource = tab2BdSrc
    End Sub
    
    Public Sub OnTab3()
        tab3BdSrc.DataSource = BLL.MyBizObj3.GetBOData3()        'Get complete data for both tables
        tab3RelBdSrc.DataSource = tab3BdSrc       'Retrieve the related rows only
        tab3RelBdSrc.DataMember = "tab3RelBdSrcobject member inside tab3BdSrc"
        If tabCommonBdNavig.BindingSource <> Nothing Then
            tabCommonBdNavig.BindingSource = Nothing
        tabCommonBdNavig.BindingSource = tab3BdSrc
    End Sub
    This code does compile, but when I execute the application, I am able to navigate only through the rows in the first data table / object using the binding navigator tool bar. When I go to 2nd and 3rd tab, the control don't seem to allow me to navigate through the records in the 2nd and 3rd data table / object respectively. I have an option of using three different navigators, but I simply do not see a reason to include that many number of binding navigators as bound data objects. There must be some way, I can change the binding source depending on the user actions. Or wait...is using generics the answer to my questions? Please let me know ...
    Thanks,
    Bhushan

  4. #4
    Join Date
    Jun 2006
    Posts
    645

    Re: Using single BindingNavigator with multiple data sources

    Well...it seems that this is not going to work. And since I have a certain deadline, I would defer it for the later. Right now, I have decided to use 3 different binding navigators and get the job done. However, they would have worked if all the different tables were on the same form. In my case, I have 3 tables under 3 different tabs. So, I think...the notification to the 2nd and 3rd tabs is not being send. Everything else looks fine...3 binding sources bound to 3 different binding navigators for 3 different tables....what else would be needed? yet the 2nd and 3rd tab pages are not reacting to the binding navigator outside the tab control. So I would like to have some info on how I could make this work...
    Thanks
    Bhushan

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

Featured