Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reusing a Dataset in Multiple Custom Controls

Status
Not open for further replies.

MrTrue

Technical User
Jul 28, 2008
46
US
I'm just looking for some general guidance here... I've created a Windows Forms application in vb.net which has several custom controls. Some of the controls have similiar elements, such as comboboxes that may contain the same data that the contrl held on one of the other controls. The comboboxes are filled with the results of a SQL query which gets passed to a binding source. Here is my question... If I want to get my bindingsource onload only and retain the data so that I can use it to refill multiple comboboxes during the duration of the user having the app open. How would I do this. Right now I create a bindingsource and tie it to the combobox everytime I create a new custom control, and since it's the exact same data it seems to me this is really inefficient. The data does not need to be updated frequently. Each time the user opens the application would be more than enough updating. Can anyone point me in the right direction, I'm more than willing to do the work, just need to know where I should be focusing my efforts. Thanks in advance for any help!
 
I may have answered my own question here, but please tell me if this is not proper...

I was able to call this from my custom control classes.. I basically just created a "Startup Class" which I set a property for when my main from loads. then I can get the property over and over (the property is a binding source)

Any thoughts on this? It seems to work, but I'm fairly new to vb.net so I want to make sure I'm not being completely ridiculous! Thank you!

Code:
Public Class StartupData
    Public Shared RsnsBind As BindingSource

    Public Shared Property RsnBS() As BindingSource
        Get
            Return RsnsBind
        End Get
        Set(ByVal Value As BindingSource)
            RsnsBind = Value
        End Set
    End Property

End Class
 

Sure, that's a perfectly acceptable wy to do this.. You could also skip the "middleman" as it were, and just Dim a BindingSource globally on the form(s). It would work the same.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top