[CLOSED] GetStore() on ComboBox with static ListItems wipes out the ListItem collection

  1. #1

    [CLOSED] GetStore() on ComboBox with static ListItems wipes out the ListItem collection

    GetStore() on ComboBox with static ListItems wipes out the ListItem collection. Try to remove this line:

    Ext.Net.Store myStore = MyCombo.GetStore();
    ... and the sample will work with no exception.

    What's happening here?

    Thank you!

    -r-

    <%@ Page Language="C#" %>
    
    <%@ Import Namespace="System.Data" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
    
            // this line will wipe out the ListItem collection
            Ext.Net.Store myStore = MyCombo.GetStore();
            //
            
            string value = MyCombo.SelectedItem.Value;
    
            if (string.IsNullOrEmpty(value))
            {
                Store store = MyCombo.GetStore();
    
                if (store != null)
                {
                    DataTable dt = null;
    
                    if (store.DataSource is DataTable)
                    {
                        dt = store.DataSource as DataTable;
                    }
    
                    if (store.DataSource is DataSet)
                    {
                        DataSet ds = store.DataSource as DataSet;
                        if (ds.Tables.Count > 0)
                        {
                            dt = ds.Tables[0];
                        }
                    }
    
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        value = Convert.ToString(dt.Rows[0][MyCombo.ValueField]);
                    }
                    else
                    {
                        value = MyCombo.Items[0].Value;
                    }
                }
            }
            
            // do something with value
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head id="Head1" runat="server">
        
    </head>
    <body>
        <form id="Form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
            
                <ext:ComboBox
                    InputWidth="350"                                                                        
    
                    ID="MyCombo"
                    runat="server"
    
                    FieldLabel="MyCombo"
                    PreselectFirstItem="True"
                    EmptyText=""
                    Editable="false" 
                    QueryMode="Local"
                    TriggerAction="All" 
    
                    AllowBlank="false">
                                            
                    <Items>
                        <ext:ListItem Text="AAA" Value="1"  />
                        <ext:ListItem Text="BBB" Value="2" />
                        <ext:ListItem Text="CCC" Value="3" />
                    </Items>
    
                </ext:ComboBox>
            
        </form>
    </body>
    </html>
    Last edited by Daniil; Oct 31, 2015 at 8:34 AM. Reason: [CLOSED]
  2. #2
    Hi @exe,

    A ComboBox's GetStore() generates a SimpleStore (not a public class) and it moves ComboBox's Items to that SimpleStore. I would say it should happen at the first .GetStore() call. I mean I would personally expect it throws an exception with only
    Store store = MyCombo.GetStore();
    Well, this exception unveils the fact that a ComboBox is not quite designed to use both - Store and Items. It supposes binding data through Store or Items, but not together.

    Though, if you need it for some reason, please use this to access a ComboBox's Store.
    Store store = MyCombo.Store.Primary;
  3. #3
    Hi Daniil,
    I just need to know, if there is a Store bound to the Combo or it uses static ListItems. I am not using them both at a time.

    I'm doing something like this:
    if (MyCombo.GetStore().StoreID != null) {
      // we have a Store
    } else {
      // we have ListItems
    }
    Or is there any other way to determine this?

    Thank you!
    Last edited by exe; Oct 30, 2015 at 2:52 PM. Reason: wrong code snippet
  4. #4
    Yes, please use if (MyCombo.Store.Primary != null) { ....
  5. #5
    Cool, close it.
    Thanks!

Similar Threads

  1. Replies: 0
    Last Post: Aug 12, 2014, 4:44 AM
  2. [CLOSED] Adding different Listitems to each ComboBox in Grid
    By blueworld in forum 2.x Premium Help
    Replies: 12
    Last Post: Mar 21, 2014, 1:26 PM
  3. [CLOSED] Can't add ListItems to ComboBox in codebehind [1.0]
    By SFritsche in forum 1.x Premium Help
    Replies: 4
    Last Post: Jul 18, 2012, 5:05 PM
  4. [CLOSED] ListItems / ComboBox - value is always a String?
    By wagger in forum 1.x Premium Help
    Replies: 1
    Last Post: Mar 31, 2011, 3:46 PM
  5. [CLOSED] adding listitems dynamically in a combobox
    By LeeTheGreek in forum 1.x Premium Help
    Replies: 5
    Last Post: Dec 22, 2009, 4:26 PM

Tags for this Thread

Posting Permissions