[CLOSED] Can not select combobox items using store

  1. #1

    [CLOSED] Can not select combobox items using store

    Hi,

    I have changed from using ListItems in a combobox to using a store. When I use a store there is nothing that I can do to make the selected item shown as selected.

    There are two methods that I can take when using list items.

    1) Call a javascript function after render to select the value
    myCombo.Listeners.AfterRender.Handler = "#{myCombo}.setValue('" & CStr(value) & "');"
    2) Add a listIem to the SelectedItems Collection to select the value.
    Dim selectedItem As New ListItem()
    selectedItem.Value = CStr(value)
    myCombo.SelectedItems.Add(selectedItem)
    Neither of these methods work when I change to using a store, I can not understand why.

    Can someone please tell me how to make a combobox show the selected value?
    Last edited by Daniil; May 21, 2012 at 8:38 AM. Reason: [CLOSED]
  2. #2
    Hi,

    I'm not too sure what's going wrong in your situation, but the following sample does appear to function correctly.

    Example

    <%@ Page Language="C#" %>
    
    <%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>
    
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            var store = this.ComboBox1.GetStore();
            
            store.DataSource = new object[]
            {
                new object[] { "Australia" }, 
                new object[] { "Austria" }, 
                new object[] { "Canada" }, 
                new object[] { "Russia" }, 
                new object[] { "United Kingdom" }
            };
    
    
            store.DataBind();
    
    
            this.ComboBox1.SelectedItems.Add(new Ext.Net.ListItem("Canada"));
        }
    </script>
    
    
    <!DOCTYPE html>
        
    <html>
    <head runat="server">
        <title>Ext.NET Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
    
    
            <ext:ComboBox
                ID="ComboBox1"
                runat="server" 
                TypeAhead="true" 
                DisplayField="name"
                QueryMode="Local">
                <Store>
                    <ext:Store runat="server">
                        <Model>
                            <ext:Model runat="server">
                                <Fields>
                                    <ext:ModelField Name="name" />
                                </Fields>
                            </ext:Model>
                        </Model>
                    </ext:Store>
                </Store>    
            </ext:ComboBox>
        </form>
    </body>
    </html>
    If this doesn't help solve the issue, then I think you're going to have to post a more complete code sample demonstrating the full scenario.
    Geoffrey McGill
    Founder
  3. #3
    <%@ Page Language="C#" %>
    
    <%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>
    
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            var store = this.ComboBox1.GetStore();
            
            store.DataSource = new object[]
            {
                new object[] {1, "Australia" },
                new object[] {2, "Austria" },
                new object[] {3, "Canada" },
                new object[] {4, "Russia" },
                new object[] {5, "United Kingdom" }
            };
    
    
            store.DataBind();
    
    
            this.ComboBox1.SelectedItems.Add(new Ext.Net.ListItem("3"));
        }
    </script>
    
    
    <!DOCTYPE html>
        
    <html>
    <head id="Head1" runat="server">
        <title>Ext.NET Example</title>
    </head>
    <body>
        <form id="Form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
    
    
            <ext:ComboBox
                ID="ComboBox1"
                runat="server"
                TypeAhead="true"
                DisplayField="name"
                ValueField="id"
                QueryMode="Local">
                <Store>
                    <ext:Store ID="Store1" runat="server">
                        <Model>
                            <ext:Model ID="Model1" runat="server">
                                <Fields>
                                    <ext:ModelField Name="id" />
                                    <ext:ModelField Name="name" />
                                </Fields>
                            </ext:Model>
                        </Model>
                    </ext:Store>
                </Store>    
            </ext:ComboBox>
        </form>
    </body>
    </html>
    I worked out the problem. When I used a name/value pair the value was an integer and the selected item was a string, hence the above code wont work.

    When I change the data-source to the following it works.

         store.DataSource = new object[]
            {
                new object[] {"1", "Australia" },
                new object[] {"2", "Austria" },
                new object[] {"3", "Canada" },
                new object[] {"4", "Russia" },
                new object[] {"5", "United Kingdom" }
            };
    Lesson learned. All values in Stores used in a combobox must be strings to be selectable.

    Thankyou for your help...
  4. #4
    Hi,

    You can use integer as values. In this case you have to set up Mode to Raw for ListItem.
    this.ComboBox1.SelectedItems.Add(new Ext.Net.ListItem() 
    { 
        Value = "3", 
        Mode = ParameterMode.Raw 
    });
    There is Value Mode by default and it causes the Value to rendered as a string.

    Setting up Mode to Raw causes the Value to be rendered as it is, i.e. as an integer.
  5. #5
    Wow, brilliant, that has saved me a lot of grief. Thank you very much for your help...

Similar Threads

  1. Can not select combobox items using store
    By blurken in forum 2.x Help
    Replies: 0
    Last Post: May 14, 2012, 1:23 AM
  2. Replies: 11
    Last Post: Mar 27, 2011, 5:26 PM
  3. Replies: 2
    Last Post: Jan 17, 2011, 3:02 PM
  4. [CLOSED] Is it possible to Select Items of a multi select during ajax event
    By vedagopal2004 in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jul 29, 2010, 6:28 PM
  5. Replies: 0
    Last Post: Feb 01, 2010, 12:42 PM

Tags for this Thread

Posting Permissions