Ticket Q245589
Visible to All Users

How to embed a ListView control with all the standard functionality into the navigation control

created 15 years ago

Hi
I would like to install a ListView into a Group on the Navigation Control (under Windows at present). The reason is that we have a ToDo list in our application, showing it via the Navigation control would allow it to be available to a user all the time.
So, I have successfully added a control to the NavBar through a Window Controller and have then extended that to add a GridControl bound to an XPCollection however this is of course very dirty and does not keep to XAF standards allowing the view to be modified via the Model etc.
So I wouuld be very grateful for any guidance you might give on how I would get a ListView to appear in a Group in the NavBar.
I have included the sample project I have been playing with using the GridControl if it is of any assistance.
Many thanks
John

Comments (1)
Dennis Garavsky (DevExpress) 15 years ago

    Hello John,
    Thanks for contacting us. I agree with you that this is a very dirty approach and you should use another solution. I suggest you utilize the standard XAF approaches to get a ListView control:

    C#
    protected override PopupBaseForm CreatePopupForm() { frame = Properties.Helper.Application.CreateFrame(TemplateContext.LookupControl); frame.CreateTemplate(); ILookupPopupFrameTemplate template = (ILookupPopupFrameTemplate)frame.Template; ListView listView = Properties.Helper.CreateListView(editingObject); frame.SetView(listView, null); ((Control)frame.Template).Dock = DockStyle.Fill; popupControl.Controls.Add((Control)frame.Template);

    This is some code from the LookupPropertyEditor class. I commented unnecessary parts and left only essential parts here.
    As you see, your goal is to create a new frame, create its template, create ListView, set it to the frame and then use the template's control as needed. The important thing is that in your case, you should create a frame based on the NestedFrameTemplate.
    Please give it a try, and let me know how this works for you.
    Thanks,
    Dennis

    Answers approved by DevExpress Support

    created 15 years ago (modified 11 years ago)

    Many thanks Dennis, an excellent answer as ever.
    For anyone interested here is the code that did it (from within a WindowController) and changes the ListView to use a CardView due to the space limitations:-
        Private Sub CreateToDoControl(ByVal group As NavBarGroup)
            Dim frame As Frame = Application.CreateFrame(TemplateContext.NestedFrame)
            frame.CreateTemplate()
            Dim template As IFrameTemplate = CType(frame.Template, IFrameTemplate)
            Dim objectSpace As ObjectSpace = Application.CreateObjectSpace
            Dim listView As DevExpress.ExpressApp.ListView = Application.CreateListView(objectSpace, GetType(Reminder), True)
            AddHandler listView.ControlsCreated, AddressOf view_ControlsCreated
            frame.SetView(listView, Nothing)
            CType(frame.Template, Control).Dock = DockStyle.Fill
            group.ControlContainer.Controls.Add(CType(frame.Template, Control))
        End Sub
        Private Sub view_ControlsCreated(ByVal sender As Object, ByVal e As EventArgs)
            Dim view As DevExpress.ExpressApp.ListView = CType(sender, DevExpress.ExpressApp.ListView)
            Dim grid As GridControl = CType(view.Control, GridControl)
            grid.MainView = New Card.CardView(grid)
            grid.MainView.PopulateColumns()
        End Sub
    Obviously it needs a bit of work for error checking, configure the CardView, Actions etc. but we have a ListView sat comfortably in the navigation bar.
    Thanks again
    John

      Comments (1)
      Dennis Garavsky (DevExpress) 15 years ago

        Hi John, thanks for the feedback and your code. You are always welcome!
        Regards,
        Dennis

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.