Я пошел вперед и подготовил для вас эксперимент (также для себя, поскольку я никогда этого не делал). Он использует Linq для этого конкретного решения, чтобы заполнить поле со списком под рукой, но я уверен, что вы могли бы заполнить его и другими способами.
Моя документация поступила от здесь в подразделе Добавление списка доменов и поддержка простого раскрывающегося списка свойств
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
public class Employee : StringConverter
{
DataClasses1DataContext mydb = new DataClasses1DataContext();
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
var a = (from u in mydb.Customers select u.CustomerID).ToArray();
return new StandardValuesCollection(a);
}
public string Name { get; set; }
[TypeConverter(typeof(Employee)), CategoryAttribute("Document Settings")]
public string DepartmentID { get; set; }
}
В форме загрузки я выбрал:
private void Form1_Load(object sender, EventArgs e)
{
Employee temp = new Employee();
propertyGrid1.SelectedObject = temp;
}
Надеюсь, это то, что вы ищете. Стоит отметить, что вы можете изменить StringConverter на TypeConverter, если хотите, но я использовал String, потому что поле, с которым я имею дело, - это строка.
