[CLOSED] ComboBox's SelectAll() method or its SelectedItems property seems out of synch

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    [CLOSED] ComboBox's SelectAll() method or its SelectedItems property seems out of synch

    Hi Ext.NET,

    From the serverside, when I invoke a SelectAll() on a combobox and then immediately check that web control's SelectedItems property, the values are not what I'd expect.
    1) click any of the buttons in my sample; first attempt the control indicates its SelectedItems property has nothing selected, immediately following a call to its SelectAll() method.
    2) clicking any of the buttons a second time is even more strange. Now, the combo box control's SelectedItems property replies back with the list of items that I expected from the first attempt.
    3) clicking a third time, the combo box control's SelectedItems property is always one step out of synch, always replying back with the values that should have been selected the last time.

    Is there some special step that I need to take after invoking SelectAll() method, to bind those selections to the web control?

    Here's my example code:
    <%@ Page Language="C#" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>MultiCombo - Ext.NET Examples</title>    
    
    <script runat="server">
        private object TestData1
        {
            get
            {
                return new object[]
                {
                    new object[] { "1A", "AVal1" },
                    new object[] { "1B", "AVal2" },
                    new object[] { "1C", "AVal3" },
                    new object[] { "1D", "AVal4" },
                    new object[] { "1E", "AVal5" },
                    new object[] { "1F", "AVal6" }
                };
            }
        }
    
        private object TestData2
        {
            get
            {
                return new object[]
                {
                    new object[] { "2A", "BVal1" },
                    new object[] { "2B", "BVal2" },
                    new object[] { "2C", "BVal3" },
                    new object[] { "2D", "BVal4" },
                    new object[] { "2E", "BVal5" },
                    new object[] { "2F", "BVal6" }
                };
            }
        }
    
        protected override void OnLoad(EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                if (!IsPostBack)
                {
                    this.TestCombo.GetStore().DataSource = TestData1;
                    this.TestCombo.GetStore().DataBind();
    
    
                    this.explicitStore.DataSource = TestData1;
                    this.explicitStore.DataBind();
                }
            }
    
        }
    
        //should work b/c any call backs to non-static serverside methods should cause the Page lifecycle to execute and allow access to all page's web controls
        [DirectMethod]
        public void DM_RefreshMultiCombo()
        {
            this.TestCombo.GetStore().DataSource = TestData1;
            this.TestCombo.GetStore().DataBind();
            this.TestCombo.SelectAll();
            lblDisplay1.Text = (this.TestCombo.SelectedItems == null || this.TestCombo.SelectedItems.Count == 0) ? "NO SELECTIONS" : String.Join(", ", this.TestCombo.SelectedItems.Select(x => x.Value));
    
            this.explicitStore.DataSource = TestData1;
            this.explicitStore.DataBind();
            this.ExplicitStoreCombo.SelectAll();
            lblDisplay2.Text = (this.ExplicitStoreCombo.SelectedItems == null || this.ExplicitStoreCombo.SelectedItems.Count == 0) ? "NO SELECTIONS" : String.Join(", ", this.ExplicitStoreCombo.SelectedItems.Select(x => x.Value));
            //unfortunately DirectMethod unable to get the multi combos to reflect 2nd dataset
        }
    
        //should also work b/c any call backs to non-static serverside methods should cause the Page lifecycle to execute and allow access to all page's web controls
        protected void DE_RefreshMultiCombo(object sender, DirectEventArgs e)
        {
            this.TestCombo.GetStore().DataSource = TestData2;
            this.TestCombo.GetStore().DataBind();     
            this.TestCombo.SelectAll();
            lblDisplay1.Text = (this.TestCombo.SelectedItems == null) ? "NO SELECTIONS" : String.Join(", ", this.TestCombo.SelectedItems.Select(x => x.Value));
            
    
            this.explicitStore.DataSource = TestData2;
            this.explicitStore.DataBind();
            this.ExplicitStoreCombo.SelectAll();
            lblDisplay2.Text = (this.ExplicitStoreCombo.SelectedItems == null) ? "NO SELECTIONS" : String.Join(", ", this.ExplicitStoreCombo.SelectedItems.Select(x => x.Value));
            //DirectEvent handler also unable to get the multi combos to reflect 2nd dataset
        }
    </script>
        
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />        
    
            <ext:Label runat="server" Text="StandardCombo's Selections:" /><ext:Label runat="server" ID="lblDisplay1" Text="...nothing yet"/>
            <br />
            
            <ext:MultiCombo runat="server" ID="TestCombo" SelectionMode="Selection" DisplayField="name" ValueField="abbr">
                 <Store>
                        <ext:Store runat="server">
                            <Model>
                                <ext:Model runat="server">
                                    <Fields>
                                        <ext:ModelField Name="abbr" />
                                        <ext:ModelField Name="name" />                                    
                                    </Fields>
                                </ext:Model>
                            </Model>
    
                            <Reader>
                                <ext:ArrayReader />
                            </Reader>
                        </ext:Store>
                    </Store>                        
            </ext:MultiCombo>
            <br />
            
            <ext:Label runat="server" Text="ExplicitStoreCombo's Selections:" /><ext:Label runat="server" ID="lblDisplay2" Text="... nothing yet" />
            <br />
            <ext:MultiCombo runat="server" ID="ExplicitStoreCombo" SelectionMode="Selection" DisplayField="name" ValueField="abbr">
                 <Store>
                        <ext:Store ID="explicitStore" runat="server">
                            <Model>
                                <ext:Model runat="server">
                                    <Fields>
                                        <ext:ModelField Name="abbr" />
                                        <ext:ModelField Name="name" />                                    
                                    </Fields>
                                </ext:Model>
                            </Model>
    
                            <Reader>
                                <ext:ArrayReader />
                            </Reader>
                        </ext:Store>
                    </Store>                        
            </ext:MultiCombo>
            <br />
    
            <ext:Button
                ID="Button1"
                runat="server"            
                Text="Load MultiCombo w/ DirectMethod"
                >
                <Listeners>
                    <Click Handler="App.direct.DM_RefreshMultiCombo();" />
                </Listeners>            
            </ext:Button>
    
            <ext:Button
                ID="Button2"
                runat="server"            
                Text="Load MultiCombo w/ DirectEvent"            
                >
                <DirectEvents>
                    <Click OnEvent="DE_RefreshMultiCombo" />
                </DirectEvents>
            </ext:Button>
        </form>
    </body>
    </html>
    Last edited by fabricio.murta; Dec 28, 2018 at 11:39 PM. Reason: no feedback from the user in 7+ days

Similar Threads

  1. Combobox.SelectedItems null value
    By Nshikov in forum 3.x Help
    Replies: 3
    Last Post: Nov 17, 2015, 11:53 AM
  2. Replies: 2
    Last Post: Sep 30, 2015, 5:52 AM
  3. Replies: 1
    Last Post: Jun 17, 2015, 12:45 PM
  4. [CLOSED] Setting SelectedItems of a combobox from MVC Model
    By hikalkan in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Apr 19, 2013, 10:50 AM
  5. Combobox SelectedItems by value icw store
    By prost in forum 2.x Help
    Replies: 1
    Last Post: Oct 23, 2012, 9:06 AM

Posting Permissions