I am using Xceed propertygrid in my project, and for some reason when I open the dropdown of the property it is showing "Xceed.Wpf.Toolkit.PropertyGrid.Attributes.Item"
instead of the items i inserted.
I am sure it is because the toString()
method is called, i just can't figure out why..
I saw this question
WPF Xceed PropertyGrid showing "Xceed.Wpf.Toolkit.PropertyGrid.Attributes.Item" instead of the real DisplayName
, this is exactly my problem but it doesn't seem that he got a solution. I have tried many attempts solution but non worked.
Any suggestions?
Asked
Active
Viewed 1,414 times
0

Community
- 1
- 1

Ravid Goldenberg
- 2,119
- 4
- 39
- 59
1 Answers
2
You can override the ToString
method to show whatever property you wanted, for example lets say we have the following class as a SelectedObject
for your propertyGrid
control:
public class Company
{
[Category("Main")]
[DisplayName("Name")]
[Description("Property description")]
public String Name { get; set; }
[Category("Main")]
[DisplayName("Type")]
[Description("Property description")]
public String Type { get; set; }
[Category("Main")]
[DisplayName("Something")]
[Description("Property description")]
public bool Something { get; set; }
[Category("Main")]
[DisplayName("Director")]
[Description("Property description")]
[ItemsSource(typeof(EmployeList))]
public Employe Director { get; set; }
}
the collection should be defined as follow
public class EmployeList : IItemsSource
{
public Xceed.Wpf.Toolkit.PropertyGrid.Attributes.ItemCollection GetValues()
{
Xceed.Wpf.Toolkit.PropertyGrid.Attributes.ItemCollection employe = new Xceed.Wpf.Toolkit.PropertyGrid.Attributes.ItemCollection();
employe.Add(new Employe()
{
Name = "Name1",
Rank = "Rank1",
Age=40,
}); employe.Add(new Employe()
{
Name = "Name2",
Rank = "Rank2",
Age=40,
}); employe.Add(new Employe()
{
Name = "Name3",
Rank = "Rank3",
Age=40,
});
return employe;
}
}
and the Employe
class should override the Tostring
method
public class Employe
{
public String Name { get; set; }
public String Rank { get; set; }
public int Age { get; set; }
public override string ToString()
{
return Name;
}
}
xaml
<xctk:PropertyGrid Name="pg" SelectedObject="{Binding SelectedCompany}" AutoGenerateProperties="True" >
</xctk:PropertyGrid>
and the result is what you are looking for

SamTh3D3v
- 9,854
- 3
- 31
- 47
-
Thank you for your answer. I have already tried this solution, the problem is that once entered into the ItemCollection, a new Item class is constructed and entered into the collection. So the ToString function called is still the Item's one. – Ravid Goldenberg Aug 18 '15 at 09:31