How to insert a combobox CustomEditor for a property that is a foreign key ID

Hi,

I have a PropertyGrid that edits an object that has an int property that represents a foreign key to a particular list of objects.
Let's say for example that the objects referenced by this foreign key have this type:

class Article
{

public int ID {get; set;}

public string Code {get; set;}

}

Let also say that I have a repository that returns the list of all articles:

IEnumerable<Article> Articles
{
get;
}

Suppose the object passed to the ProperyGrid has a property like this:

int ArticleID {get; set;}

How is it possibile to change the default behaviour of PropertyGrid on property named "ArticledID"?

I don't want, in fact, an integer textbox edit, but instead I'd like to a have a ComboBox populated by "Articles" repository property, showing the "Code" property as Display property but using the "ID" property as Value property.

Thank you in advance.

Silvio

1 Reply

VI Vinothini Syncfusion Team August 25, 2016 11:06 AM UTC

Hi Silvio, 

Thank you for contacting Syncfusion support. 

The ComboBox can be added to the Property grid using the CustomEditorCollection property. We need to implement a Custom editor with ITypeInterface. Please refer the code example for adding ComboBox in ArticleID property. 

[C#] 

 
pgrid.SelectedObject = new Article(); 
CustomEditor editor = new CustomEditor(); 
editor.Editor = new ComboEditor(); 
editor.Properties.Add("ArticleID"); 
this.pgrid.CustomEditorCollection.Add(editor); 
pgrid.RefreshPropertygrid(); 



We have prepared sample for the sample which is available in the below location. 


Regards, 
Vinothini.R 


Loader.
Up arrow icon