[CLOSED] Adding extra listitem at top combobox

  1. #1

    [CLOSED] Adding extra listitem at top combobox

    Hi,

    Trying to add an extra listitem in your Ajax Linked Combos example.
    How to Achieve. I've tried combo.Items.Insert, but not succeeding. Where do I go wrong ?

    <%@ Page Language="C#" %>
    <%@ Import Namespace="System.Collections.Generic" %>
    <%@ Import Namespace="System.Xml" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html>
    <html>
    <head runat="server">
        <title>Ext.NET Examples</title>
        <script runat="server">
            protected void CitiesRefresh(object sender, StoreReadDataEventArgs e)
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(HttpContext.Current.Server.MapPath("Cities.xml"));
                List<object> data = new List<object>();
                foreach (XmlNode cityNode in xmlDoc.SelectNodes(string.Concat("countries/country[@code='", this.ComboBox1.SelectedItem.Value, "']/city")))
                {
                    string id = cityNode.SelectSingleNode("id").InnerText;
                    string name = cityNode.SelectSingleNode("name").InnerText;
                    data.Add(new { Id = id, Name = name });
                }
                
                this.CitiesStore.DataSource = data;
                this.CitiesStore.DataBind();
    // -- CHECK THIS --
                Ext.Net.ListItem li = new Ext.Net.ListItem("New","0");
                ComboBox2.Items.Insert( 0 , li );
            }
        </script>
        <link href="/resources/css/examples.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
    <form runat="server">
        <ext:ResourceManager runat="server" />
        
        <ext:ComboBox 
            ID="ComboBox1" 
            runat="server" 
            Editable="false" 
            TypeAhead="true" 
            QueryMode="Local"
            ForceSelection="true" 
            TriggerAction="All" 
            SelectOnFocus="true" 
            EmptyText="Select a country">
            <Listeners>
                <Select Handler="#{ComboBox2}.clearValue(); #{CitiesStore}.reload();" />
            </Listeners>        
            <Items>
                <ext:ListItem Text="Belgium" Value="BE" />
                <ext:ListItem Text="Brazil" Value="BR" />
                <ext:ListItem Text="Bulgaria" Value="BG" />
                <ext:ListItem Text="Canada" Value="CA" />
                <ext:ListItem Text="Chile" Value="CL" />
                <ext:ListItem Text="Cyprus" Value="CY" />
                <ext:ListItem Text="Finland" Value="FI" />
                <ext:ListItem Text="France" Value="FR" />
                <ext:ListItem Text="Germany" Value="DE" />
                <ext:ListItem Text="Hungary" Value="HU" />
                <ext:ListItem Text="Ireland" Value="IE" />
                <ext:ListItem Text="Israel" Value="IL" />
                <ext:ListItem Text="Italy" Value="IT" />
                <ext:ListItem Text="Lithuania" Value="LT" />
                <ext:ListItem Text="Mexico" Value="MX" />
                <ext:ListItem Text="Netherlands" Value="NL" />
                <ext:ListItem Text="New Zealand" Value="NZ" />
                <ext:ListItem Text="Norway" Value="NO" />
                <ext:ListItem Text="Pakistan" Value="PK" />
                <ext:ListItem Text="Poland" Value="PL" />
                <ext:ListItem Text="Romania" Value="RO" />
                <ext:ListItem Text="Slovakia" Value="SK" />
                <ext:ListItem Text="Slovenia" Value="SI" />
                <ext:ListItem Text="Spain" Value="ES" />
                <ext:ListItem Text="Sweden" Value="SE" />
                <ext:ListItem Text="Switzerland" Value="CH" />
                <ext:ListItem Text="United Kingdom" Value="GB" />
            </Items>
        </ext:ComboBox>
        
        <ext:ComboBox 
            ID="ComboBox2" 
            runat="server" 
            TypeAhead="true" 
            QueryMode="Local"
            ForceSelection="true" 
            TriggerAction="All" 
            DisplayField="name" 
            ValueField="id"
            EmptyText="Loading..." 
            ValueNotFoundText="Loading...">
            <Store>
                <ext:Store 
                    runat="server" 
                    ID="CitiesStore" 
                    AutoLoad="false" 
                    OnReadData="CitiesRefresh">               
                    <Model>
                        <ext:Model runat="server" IDProperty="Id">
                            <Fields>
                                <ext:ModelField Name="id" Type="String" Mapping="Id" />
                                <ext:ModelField Name="name" Type="String" Mapping="Name" />
                            </Fields>
                        </ext:Model>
                    </Model>
                    <Listeners>
                        <Load Handler="#{ComboBox2}.setValue(#{ComboBox2}.store.getAt(0).get('id'));" />
                    </Listeners>
                </ext:Store>
            </Store>    
        </ext:ComboBox>
    </form>
    </body>
    </html>
    Last edited by Daniil; Jul 04, 2012 at 2:28 PM. Reason: [CLOSED]
  2. #2
    Hi,

    Please do not mix the ComboBox Store and Items. They should not be used at the same time.

    I would add the new item into the "data" before it is applying to the Store DataSource.
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi,

    Please do not mix the ComboBox Store and Items. They should not be used at the same time.

    I would add the new item into the "data" before it is applying to the Store DataSource.
    Ok..

    Will do that. Thanks..

    Martin
  4. #4
    Combobox can use store data and Items at one time but Items must be defined initialy (before rendering)
    For example, move ListItem to Items collection initially and 'New' item will be appended after each store reloading
    <Items>
                <ext:ListItem Text="New" Value="0" />
            </Items>
  5. #5
    I have to clarify the following.

    Quote Originally Posted by Daniil View Post
    Please do not mix the ComboBox Store and Items. They should not be used at the same time.
    It regards to DirectEvent/DirectMethod. Though, personally, I would avoid to use Store and Items at the same time for initial page load as well.

Similar Threads

  1. [CLOSED] ComboBox empty ListItem
    By methode in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Nov 18, 2013, 4:01 AM
  2. [CLOSED] ext:ComboBox ListItem with html image tag
    By supera in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Apr 02, 2012, 12:58 PM
  3. Replies: 3
    Last Post: Sep 23, 2010, 2:45 PM
  4. Replies: 0
    Last Post: May 30, 2010, 10:24 PM
  5. ComboBox ListItem Selected
    By Timothy in forum Bugs
    Replies: 1
    Last Post: Aug 22, 2008, 2:51 PM

Posting Permissions