PDA

View Full Version : [CLOSED] PropertyGrid not getting refreshed



jainanki
Jan 13, 2014, 9:52 PM
I am struggling with an issue in the PropertyGrid control of Ext.Net library. A page in my application has a dynamic tree structure:

7480

which on the click of any node in the tree populates the PropertyGrid.

7481

So far so good. The issue starts with a click on another node in the tree. The values get refreshed, but a property that is no longer present for the new node, still remains in the PropertyGrid.

7482

I started with this code to add properties to the grid,


private PropertyGridParameterCollection propCollection;

PropertyGridParameter propGridParameter = new PropertyGridParameter();
propCollection.Add(propGridParameter);

this.propGrdTlbox.Source.AddRange(propCollection);
this.propGrdTlbox.DataBind();

but it never worked. So I resorted to using:


this.propGrdTlbox.AddProperty(propGridParameter);

Suggest me what am I missing here?

Daniil
Jan 14, 2014, 5:23 AM
Hi @jainanki,

Welcome to the Ext.NET forums!

Please use the SetSource method.

Example

PropertyGridParameterCollection source = new PropertyGridParameterCollection();
PropertyGridParameter propGridParameter = new PropertyGridParameter("prop1", "value1");
source.Add(propGridParameter);
propGridParameter = new PropertyGridParameter("prop2", "value2");
source.Add(propGridParameter);
this.PropertyGrid1.SetSource(source);

jainanki
Jan 14, 2014, 4:36 PM
Hi Daniil,

I had already tried that code, in fact that was the first thing I tried. It didn't work this time also.

Any other suggestion?

Thanks,
ankit

Daniil
Jan 15, 2014, 3:04 AM
It appears to be working in this example. Please provide your test case.

Example

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
protected void SetSource1(object sender, DirectEventArgs e)
{
PropertyGridParameterCollection source = new PropertyGridParameterCollection();
PropertyGridParameter propGridParameter = new PropertyGridParameter("new prop1", "new value1");
source.Add(propGridParameter);
propGridParameter = new PropertyGridParameter("new prop2", "new value2");
source.Add(propGridParameter);
this.PropertyGrid1.SetSource(source);
}

protected void SetSource2(object sender, DirectEventArgs e)
{
PropertyGridParameterCollection source = new PropertyGridParameterCollection();
PropertyGridParameter propGridParameter = new PropertyGridParameter("new new prop1", "new new value1");
source.Add(propGridParameter);
propGridParameter = new PropertyGridParameter("new new prop2", "new new value2");
source.Add(propGridParameter);
this.PropertyGrid1.SetSource(source);
}
</script>

<!DOCTYPE html>
<html>
<head runat="server">
<title>Ext.NET v2 Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />

<ext:Button runat="server" Text="SetSource 1" OnDirectClick="SetSource1" />
<ext:Button runat="server" Text="SetSource 2" OnDirectClick="SetSource2" />

<ext:PropertyGrid ID="PropertyGrid1" runat="server">
<Source>
<ext:PropertyGridParameter Name="prop1" Value="value1" />
<ext:PropertyGridParameter Name="prop2" Value="value2" />
</Source>
</ext:PropertyGrid>
</form>
</body>
</html>

jainanki
Jan 15, 2014, 1:46 PM
Hi Daniil,

Here is my code. We are using Combo, MultiSelect, Text as Editor for the PropertyGridParameter, depending on the type of property. I am only pasting code for one type.


PropertyGridParameterCollection propCollection = new PropertyGridParameterCollection();

foreach (Property prop in defControl.Properties)
{
PropertyGridParameter propGridParameter = new PropertyGridParameter();
propGridParameter.Name = prop.PropertyName;

ComboBox cmb = new ComboBox();
foreach (PropertyValue value in defaultPropertyValues)
{
cmb.Items.Add(new EpicListItem(value.PropertyValue, value.PropertyValue));
}
propGridParameter.Editor.Add(cmb);

propCollection.Add(propGridParameter);
}
this.propGrdTlbox.SetSource(propCollection);


With SetSource(), I get Javascript Syntax error. Hence, I resorted to using AddProperty() method.

Daniil
Jan 15, 2014, 2:24 PM
Yes, the SetSource method doesn't support Editors.

In this case I recommend to re-render the PropertyGrid:
http://forums.ext.net/showthread.php?20703&p=89360&viewfull=1#post89360