May 28, 2014, 3:26 PM
[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
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]