属性网格字段的自动完成
我有一个类,我将其设置为属性网格的源对象。这些值来自值列表:
class Person
{
...
[TypeConverter(NationalityStringConverter)]
public string Nationality
...
class NationalityStringConverter: StringConverter
{
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return true;
}
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
// return my value collection
现在是我的问题。可以将此列表作为建议列表。以同样的方式,您可以将其设置为 ComboBox,例如:
comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;
Thx 4 个答案
I've a class which I set as source object to a property grid. The values are coming from a value list:
class Person
{
...
[TypeConverter(NationalityStringConverter)]
public string Nationality
...
class NationalityStringConverter: StringConverter
{
public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
{
return true;
}
public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
{
return true;
}
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
{
// return my value collection
Now my question. It it possible to make this list as a suggestion list. In the same way you would set it to a ComboBox like:
comboBox1.AutoCompleteMode = AutoCompleteMode.SuggestAppend;
comboBox1.AutoCompleteSource = AutoCompleteSource.ListItems;
Thx 4 answers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需尝试访问由属性网格添加的组合框项。
我不知道这是否可行,但值得一试;)
Just try to access the Combobox item which is added by the property grid.
I don't know if this is feasible, but worth a try ;)
如果您创建自定义 UITypeEditor,您应该能够覆盖该行为并创建您自己的列表框,您可以在使用 IWindowsFormsEditorService.DropDownControl 调用 EditValue 时显示该列表框。这可能会让您获得所需的控制权。
PropertyGrid 还有一个 ControlAdded 事件,您可以使用它来访问它创建的用于编辑的列表框。
我目前正在与 PropertyGrid 进行斗争,所以我不确定这些选项中的任何一个是否可以满足您的需求,但它可能会有所帮助。
If you create a custom UITypeEditor you should be able to override the behaviour and create your own listbox which you can display when EditValue is called using IWindowsFormsEditorService.DropDownControl. That might give you access to the control you need.
The PropertyGrid also has a ControlAdded event, you might be able to use that to get access to the listbox it creates for editing.
I'm currently wrestling with the PropertyGrid myself so I'm not sure if either of these options gives you what you need, but it may help.