[CLOSED] Combo selected text

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] Combo selected text

    Hi
    How do I get the text (via a direct event) entered in a combobox when ForceSelection = false and the user enters a value which is NOT in the list of items? In Ext.Net 2.0 .SelectedIem.Text currently throws an error (Object reference not set to an instance of an object).

    Thanks.
    Last edited by geoffrey.mcgill; Jan 26, 2012 at 4:37 AM. Reason: [CLOSED]
  2. #2
    Hi,

    Thanks for the report.

    There is no way to get it in DP1 apart from a DirectEvent's extra parameter, a text is not automatically submitted from client.

    We will fix it.

    For now, I'm not sure it will be the same as it's in v1, i.e. getting that text from SelectedItem.Text, because it's not really a selected item, so, not logical.

    We will fix and update the thread.
  3. #3
    Thanks Daniil
    Could you tell me if the fix will be available via SVN in a reasonable timeframe or will we have to wait until DP2 - which I assume is dependant on ExtJs4.1 (scheduled for late March)?

    I have a lot of comboboxes which accept both selected items and custom text so in order to continue building in Ext 2.0 I need to be able to both get and set custom text.

    Thanks,
    Adrian.
  4. #4
    Quote Originally Posted by Adrian View Post
    Thanks Daniil
    Could you tell me if the fix will be available via SVN in a reasonable timeframe or will we have to wait until DP2 - which I assume is dependant on ExtJs4.1 (scheduled for late March)?

    I have a lot of comboboxes which accept both selected items and custom text so in order to continue building in Ext 2.0 I need to be able to both get and set custom text.

    Thanks,
    Adrian.
    We are fixing, and will post the source-code changes here. This will enable you to just patch your local Ext.NET source files and recompile.

    The official fix will be included in the next Ext.NET v2 release, which will include Ext JS 4.1 Beta 2.
    Geoffrey McGill
    Founder & CEO
  5. #5
    That's great. Thank you.

    A.
  6. #6
    The fix has been added to SVN.

    Here is the new code of LoadPostData in ComboBoxBase.cs .

    Fix (Ext.Net\Ext\Form\ComboBoxBase.cs)
    protected override bool LoadPostData(string postDataKey, NameValueCollection postCollection)
    {
        this.HasLoadPostData = true;
    
        string text = postCollection[this.UniqueName];
        string state = postCollection["_" + this.UniqueName + "_state"];
    
        this.SuspendScripting();
        this.RawValue = text;
        this.Value = text;
        this.ResumeScripting();
    
        if (state == null && text == null)
        {
            return false;
        }
    
        if (!this.EmptyText.Equals(text) && text.IsNotEmpty())
        {
            List<ListItem> items = null;
            if (this.SimpleSubmit)
            {
                var array = state.Split(new char[] { ',' });
                items = new List<ListItem>(array.Length);
                foreach (var item in array)
                {
                    items.Add(new ListItem(item));
                }                    
            }
            else if(state.IsNotEmpty())
            {
                items = ComboBoxBase.ParseSelectedItems(state);
            }
    
            bool fireEvent = false;
    
            if (items == null)
            {
                items = new List<ListItem> 
                { 
                    new ListItem(text)
                };                    
                        
                /*fireEvent = this.SelectedItems.Count > 0;
                this.SelectedItems.Clear();
                return fireEvent;
                */
            }
    
            foreach (var item in items)
            {
                if (!this.SelectedItems.Contains(item))
                {
                    fireEvent = true;
                    break;
                }
            }
    
            this.SelectedItems.Clear();
            this.SelectedItems.AddRange(items);
    
            return fireEvent;
        }
        else
        {
            if (this.EmptyText.Equals(text) && this.SelectedItems.Count > 0)
            {
                this.SelectedItems.Clear();
    
                return true;
            }
        }
                
        return false;
    }
  7. #7
    Thanks for the updated code Daniil.

    So that we get the new approach correct, could you please provide an example - based on Ext.Net 2.0 - using DirectEvents, for:

    1. Assigning values to a combobox (when forceselection = false) and the value could be either present, or not present, in the list of items i.e. what approach should be taken now instead of combobox1.SelectedItem.Text = "Some Value".

    2. Reading values from a combobox when items are both present in the list and not present.

    Appreciate your assistance,
    Adrian.
  8. #8
    Hi,

    Here you are.

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void GetValue(object sender, DirectEventArgs e)
        {
            string v = this.ComboBox1.SelectedItem.Value;
            string t = this.ComboBox1.SelectedItem.Text;
            string msg = string.Format("Text: {0}<br/>Value: {1}", t, v);
            X.Msg.Alert("ComboBox", msg).Show();
        }
    
        protected void SetItem(object sender, DirectEventArgs e)
        {
            this.ComboBox1.Value = "2";
            
            //or
            
            //this.ComboBox1.Text = "2";
    
            //or
            
            //this.ComboBox1.SetValue("2");
        }
    
        protected void SetText(object sender, DirectEventArgs e)
        {
            this.ComboBox1.Value = "Hello World!";
    
            //or
    
            //this.ComboBox1.Text = "Hello World!";
    
            //or
    
            //this.ComboBox1.SetValue("Hello World!");
        }
    </script>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:ComboBox ID="ComboBox1" runat="server" LazyMode="Instance">
                <Items>
                    <ext:ListItem Text="Item 1" Value="1" />
                    <ext:ListItem Text="Item 2" Value="2" />
                </Items>
                <SelectedItems>
                    <ext:ListItem Index="0" />
                </SelectedItems>
            </ext:ComboBox>
            <ext:Button runat="server" Text="Get value" OnDirectClick="GetValue" />
            <ext:Button runat="server" Text="Set item" OnDirectClick="SetItem" />
            <ext:Button runat="server" Text="Set text" OnDirectClick="SetText" />
        </form>
    </body>
    </html>
  9. #9
    Thanks Daniil. Much appreciated.

    A.
  10. #10
    Hi Daniil,
    Using your example it is still the case that if you type a custom entry which is not in the list of items both ComboBox1.SelectedItem.Text and ComboBox1.Text (or ComboBox1.Value) fail to retrieve the correct text/value - the text/value will default to the previous selected list item.

    Also, if a combo box is not assigned a pre-selected value (ie it is left blank) and the user does not select a listed item, but rather enters a custom value, you will get an 'Object reference not set to an instance of an object' error on a direct event.

    Thanks for your ongoing help.
    Adrian.
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 6
    Last Post: Aug 25, 2011, 2:13 PM
  2. [CLOSED] Combo Clearing Selected Text in IE?
    By peter.campbell in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jul 11, 2011, 11:51 AM
  3. Replies: 3
    Last Post: Aug 21, 2010, 5:26 AM
  4. [CLOSED] get more than one text from combo box
    By sharif in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Apr 07, 2010, 10:13 AM
  5. Replies: 10
    Last Post: Apr 05, 2010, 1:42 AM

Tags for this Thread

Posting Permissions