Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
180
dynamic more Items in UltraCombo
posted

Hi

I am getting data to my ultracombo from a webservice.

There are some 50,000 records but we sensibly provide a most recently used subset and dynamically

filter as the user is typing.

If the user does not see the entry they want, we want a mechanism whereby they can reqest more data.

I've tried a few options none of which i cant get working

1. Catch the scroll event and if the scrollbar is at the bottom more data will be requested similar to when you search for images in google and start scrolling down.

this doesnt work because there doesnt seem to be any event to figure this out and SPY++ shows that the WM_VSCROLL event isnt being sent.. Adding a WndProc handler shows the same.

2.Add a fake summary row with a hard coded "Click for more" text and catch the mouse click event.

Again there is no event handler and SPY++ shows no mouse click events are being sent

3. Add a fake row at the end with hard coded "Click for more"

Still no mouse click events so the only (hacky) way I can find is to catch the value changed event and

see if the text is "Click for more" but after that the drop down closes. calling Toggle drop down in that event handler is too early and it closes afterwards.

Also for this solution I would need to merge the multiple columns in this row somehow or do a custom paint over it.

I hope you get what I am tryong to acheive, any nice solution will do.

thanks

Michael

Parents
  • 469350
    Offline posted

    Hi Michael,

    Your idea of using a fake summary row (or data row) is not bad. But as you noticed, you cannot catch mouse events on the dropdown portion of the combo - at least not easily.

    I found a way to do this using a CreationFilter to insert a custom button UIElement into the dropdown.

    So I add a fake summary to the combo:


            private void ultraCombo1_InitializeLayout(object sender, InitializeLayoutEventArgs e)
            {
                UltraGridLayout layout = e.Layout;
                UltraGridBand band = layout.Bands[0];
                UltraGridOverride ov = layout.Override;

                band.Summaries.Add("Fake", null);
                ov.SummaryFooterCaptionVisible = DefaultableBoolean.False;
            }

    And I create a class which inherits from ButtonUIElement and override the OnClick method.


        internal class ComboLoadMoreDataButtonUIElement : ButtonUIElement
        {
            public ComboLoadMoreDataButtonUIElement(UIElement parent)
                : base(parent)
            { }

            protected override void OnClick()
            {
                base.OnClick();
            }
        }

    Then I create a CreationFilter class that watches for the SummaryFooterUIElement and replaces the entire contents of this element with my custom button element.


       
        internal class ComboLoadMoreDataCreationFilter : IUIElementCreationFilter
        {
            #region IUIElementCreationFilter Members

            void IUIElementCreationFilter.AfterCreateChildElements(UIElement parent)
            {
                // do nothing
            }

            bool IUIElementCreationFilter.BeforeCreateChildElements(UIElement parent)
            {
                SummaryFooterUIElement summaryFooterUIElement = parent as SummaryFooterUIElement;
                if (summaryFooterUIElement != null)
                {
                    ComboLoadMoreDataButtonUIElement comboLoadMoreDataButtonUIElement = null;

                    // See if there is an existing element we can re-use.
                    if (parent.ChildElements.Count > 0)
                    {
                        foreach (UIElement childElement in parent.ChildElements)
                        {
                            if (childElement is ComboLoadMoreDataButtonUIElement)
                            {
                                comboLoadMoreDataButtonUIElement = (ComboLoadMoreDataButtonUIElement)childElement;
                                break;
                            }
                        }
                    }

                    parent.ChildElements.Clear();

                    if (comboLoadMoreDataButtonUIElement == null)
                        comboLoadMoreDataButtonUIElement = new ComboLoadMoreDataButtonUIElement(parent);

                    comboLoadMoreDataButtonUIElement.Rect = parent.Rect;
                    parent.ChildElements.Add(comboLoadMoreDataButtonUIElement);
                    return true;
                }

                return false;
            }

            #endregion
        }

     

    And you just have to attach the CreationFilter to the combo up front. I'd do this in Form_Load.

     


                this.ultraCombo1.CreationFilter = new ComboLoadMoreDataCreationFilter();

  • 180
    posted in reply to Mike Saltzman

    Hi Mike

    That worked a treat:

    Few points though.

    I need a mechanism to communicate bewteen this UIElement and the UltraCombo for things like,

    • getting the colours from the styleset of the UltraCombo ; at the moment I'm using hard coded values
    • getting information about the rows so I can figure out what to display  - e.g. "displaying 25 of 80 "
    • sending the click event up to the UltraCombo so it can do something to get the next bit of data

    At the moment I can do all of the above by tweaking the constructors of the CreationFilter and uielement to pass in the UltraCombo - it just feels a little bit of a hack.

    Also the fake button doesnt actually behave like a button, i.e. I don't see it looking pressed when I click on it. I don't need that functionality (in fact i may make mine look like a hyperlink), but is more for completeness for anyone else reading this.

    thanks

    Michael

Reply Children