[CLOSED] Combobox value in PropertyGrid

  1. #1

    [CLOSED] Combobox value in PropertyGrid

    Hi,

    When I use a ComboBox as editor in a PropertyGrid, the selected Text is not displayed correctly. I found a post which explained to use a render function for displaying the correct text.

    http://forums.ext.net/showthread.php...ombobox-editor

    This however only works when the value field has a integer value, not when it is a string. Somehow the selected value will be surrounded with quotes when it has a non integer value. "A" becomes "\"A\"".
    When saving the PropertyGrid values, the selected value will have surrounding quotes.

    Why is it working this way?

    I use Ext.NET version: 2.5.1.25544

    An other question: how do I change the width of the first column in the property grid? (I found some old samples on the forum, they don't work with the current version).

    Thanks!
    Sander

    <%@ Page Language="C#" %>
    
    <script runat="server">
    
    
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                var stringKeyGridParameter = new PropertyGridParameter
                {
                    Name = "StringKeyProp",
                    DisplayName = "String Key Property - long label name",
                    Value = "A"
                };
                var editor = new ComboBox
                {
                    ForceSelection = true,
                    ID = stringKeyGridParameter.Name + "_Editor",
                    Items = 
                    {
                        new Ext.Net.ListItem("Value A", "A")
                    }
                };
                stringKeyGridParameter.Editor.Add(editor);
                stringKeyGridParameter.Renderer.Handler = string.Format("return renderPropGridCombo({0},value);", editor.ClientID);
                PropGrid.AddProperty(stringKeyGridParameter);
    
    
    
    
                var intKeyGridParameter = new PropertyGridParameter
                {
                    Name = "IntKeyProp",
                    DisplayName = "Int Key Property - long label name",
                    Value = "1"
                };
                editor = new ComboBox
                {
                    ForceSelection = true,
                    ID = intKeyGridParameter.Name + "_Editor",
                    Items = 
                    {
                        new Ext.Net.ListItem("Value 1", "1")
                    }
                };
                intKeyGridParameter.Editor.Add(editor);
                intKeyGridParameter .Renderer.Handler = string.Format("return renderPropGridCombo({0},value);", editor.ClientID);
                PropGrid.AddProperty(intKeyGridParameter);
            }
        }
    
    
        public void OnSaveButtonClick(object sender, DirectEventArgs e)
        {
            var intKeyProp = PropGrid.Source.FirstOrDefault(x => x.Name == "IntKeyProp");
            var isTrue = intKeyProp.Value == "1";
    
    
            var stringKeyProp = PropGrid.Source.FirstOrDefault(x => x.Name == "StringKeyProp");
            var isTrue2 = stringKeyProp.Value == "\"A\"";
        }
    
    
    </script>
    
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title></title>
        <ext:XScript ID="XScript2" runat="server">
            <script type="text/javascript">
                function renderPropGridCombo(combo, value) {
                    if (value == '' || value === undefined) return '';
                    var r = '';
                    var store = combo.getStore();
                    for (var i = 0; i < store.data.items.length; i++) {
                        var item = store.data.items[i];
                        var v = item.data[combo.valueField];
                        if (v == value) {
                            return item.data[combo.displayField];
                        }
                    }
                    return '';
                }
            </script>
        </ext:XScript>
    </head>
    <body>
        <form id="Form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
            <ext:PropertyGrid ID="PropGrid" runat="server"
                ForceFit="true"
                Height="200"
                Width="300">
                <Buttons>
                    <ext:Button ID="SaveButton" runat="server" Text="Save">
                        <DirectEvents>
                            <Click OnEvent="OnSaveButtonClick" />
                        </DirectEvents>
                    </ext:Button>
                </Buttons>
            </ext:PropertyGrid>
        </form>
    </body>
    </html>
    Last edited by Daniil; Jun 02, 2014 at 12:40 PM. Reason: [CLOSED]
  2. #2
    Hi Sander,

    A PropertyGrid's AddProperty method must be used during DirectEvents/DirectMethods only.

    Please replace
    PropGrid.AddProperty(stringKeyGridParameter);
    with
    PropGrid.Source.Add(stringKeyGridParameter);
    The same is for the intKeyGridParameter.

    Though, it leads to another issue. You'll get a NullException, because the PropertyGrid's will be empty. You should remove
    if (!X.IsAjaxRequest)
    to let the Source to be recreated on each request. I'd say it is required if you want to work with a PropertyGrid's Source during a DirectEvent.

    Going further, to have an int value on client, you should use ParameterMode.Raw here:
    var intKeyGridParameter = new PropertyGridParameter
    {
        Name = "IntKeyProp",
        DisplayName = "Int Key Property - long label name",
        Value = "1",
        Mode = ParameterMode.Raw
    };
    Now, this line
    var isTrue = intKeyProp.Value == "1";
    A PropertyGridParameter's Value property is a type of string. So, it cannot be an int value here. You should cast it by your own.

    An other question: how do I change the width of the first column in the property grid? (I found some old samples on the forum, they don't work with the current version).
    Please start a new forum thread. Posting a link to the thread with the old sample that you found is also appreciated.
  3. #3
    Following worked for me:
    Mode = ParameterMode.Raw

    Thx!

Similar Threads

  1. how to show combobox in the PropertyGrid?
    By hongxue in forum 2.x Help
    Replies: 17
    Last Post: Jun 07, 2013, 12:38 PM
  2. Replies: 2
    Last Post: Apr 12, 2013, 1:42 PM
  3. [CLOSED] PropertyGrid with combobox editor
    By Marcelo in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Mar 14, 2012, 11:16 PM
  4. [CLOSED] PropertyGrid Combobox
    By Marcelo in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Jun 27, 2011, 6:56 PM
  5. [CLOSED] Combobox in PropertyGrid
    By bakardi in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Jun 07, 2011, 4:19 PM

Tags for this Thread

Posting Permissions