Forums

Binding a UI Property to XtraUserControl Property

Last post 7/7/2009 7:04 AM by Stephen Nyikos. 2 replies.
Sort Posts: Previous Next
  • Stephen Nyikos

    Binding a UI Property to XtraUserControl Property

    7/3/2009 3:32 PM
    • Not Ranked
    • Joined on 1/22/2008
    • Posts 16

    Hi,

    I have a project with multiple tabs on an XtraTabControl. Each tab is specific to a defect in a process and entered by someone while working. Because each tab contains the same group of controls, I created one XtraUserControl which contains some public properties specific to the defect object it contains. There can be 10+ tabs, so this really reduces code and makes it much easier to process the input.

    The thing I'm after is an event or something so that when the user changes the user control's values contained in the user control, the owning tab's caption changes to a specific property in the defect object. Is there a design time way to do this or is best to code the binding in the load event? It seems too much to code a new event for this, but how else would one do it if not through data binding?

    Thanks in advance,

    Sn

  • Robert Chaffe

    Re: Binding a UI Property to XtraUserControl Property

    7/6/2009 8:47 PM
    • Top 50 Contributor
    • Joined on 5/4/2007
    • Dallas, Texas
    • Posts 880
    Answer
    One possibility would be to let your user control have a reference to the tab page that contains it.  Upon construction or loading of the object that contains the tab control, loop through the tab page collection and invoke a method or property that embeds the reference.  Then, when the appropriate value is changed within the user control, it can directly access the tab page's Text property.
     
    __________
     
    // Assuming that the MyDefectUserControl instance is the first or only control in each tab page.  (C#)
    foreach( XtraTabPage tabPage in tabControl1.TabPages )
        ((MyDefectUserControl) tabPage.Controls[ 0 ]).SetTabPage( tabPage );
    __________
     
    If tab pages are dynamically created and added to the tab control, then each instance of the user control would also be dynamically created and added to each tab page.  In this case, the constructor of the user control could receive a reference to the just constructed tab page.
     
    If, instead, you want the tab page to receive an event raised by its user control, consider subclassing the XtraTabPage class.
     
  • Stephen Nyikos

    Re: Binding a UI Property to XtraUserControl Property

    7/7/2009 7:04 AM
    • Not Ranked
    • Joined on 1/22/2008
    • Posts 16

     Good suggestion. I added a constructor, a public property, and a method or two to set the XtraTabPage owning the control. Works well. When the property changes, I set the tab's caption in the setter of the property I need to target.

    Thanks!

    _Sn

More from DevExpress
Live Chat
Have a pre-sales question?
Need assistance with your evaluation?
We are here to help.
Chat is one of the many ways you can contact members of the DevExpress Team. We are available Monday-Friday between 8:30am and 5:00pm Pacific Time.
If you need additional product information, require pre-sales assistance, or want help with your order, write to us at info@devexpress.com or call us at
+1 (818) 844-3383.