As shown above, on advPropertyGrid add an attribute, the attribute value is optional in a drop-down list, and now the attribute value can be manually entered does not exist in the drop-down list of values, I want to make it below the attribute value is set in the form of, is not allowed to enter the value, what method?
CodePudding user response:
Can drop down again, again how can enter?CodePudding user response:
Then it is good to use a combobox or dropdownlist directly,CodePudding user response:
Don't know, controls own drop-down list like this, may be similar to the combobox dorpdownCodePudding user response:
How to use directly the combobox dropdownlist?CodePudding user response:
I how do not, what is it you this binding type of variable, or we use the different versionCodePudding user response:
You are using is PropertyGrid control or DotNetBar AdvPropertyGrid? PropertyGrid did not enter, but AdvPropertyGrid can, I also don't understand why the environment is. Net Core of 3.0CodePudding user response:
Public class OptionCollectionAttribute: System. The Attribute{
///& lt; summary>
///the constructor
///& lt;/summary>
///& lt; Param name="optionValues & gt;" Comma-separated list of items to choose (example: "A, B, C") & lt;/param>
Public OptionCollectionAttribute (string optionValues)
{
if (! String. IsNullOrEmpty (optionValues))
{
String [] spliter=new string [] {} ", ";
String [] values=optionValues. Split (spliter, StringSplitOptions RemoveEmptyEntries);
If (values!=null & amp; & Values. The Length & gt; 0)
{
_OptionCollection. AddRange (values);
}
}
}
List
///& lt; summary>
///for collection of the various options
///& lt;/summary>
Public List
{
The get {return _OptionCollection; }
}
}
Public partial class OptionValuesTypeConvertor: StringConverter
{
Public override bool GetStandardValuesSupported (ITypeDescriptorContext context)
{
return true;
}
Public override bool GetStandardValuesExclusive (ITypeDescriptorContext context)
{
return true;
}
Public override TypeConverter. StandardValuesCollection GetStandardValues (ITypeDescriptorContext context)
{
If (context. The Instance==null)
Return to base. GetStandardValues (context);
//find the current operation of attribute
System. Reflection. PropertyInfo [] propertyInfos=context. The Instance. The GetType (). The GetProperties ();
System. Reflection. PropertyInfo currentProperty=null;
Foreach (System. Reflection. PropertyInfo info in propertyInfos)
{
If (info. Name==context. PropertyDescriptor. Name)
{
CurrentProperty=info;
break;
}
}
If (currentProperty==null)
Return to base. GetStandardValues (context);
//find OptionCollectionAttribute of attributes for the current operation feature, and according to the feature worth to selection
Object [] optionCollectionAttributes=currentProperty. GetCustomAttributes (typeof (OptionCollectionAttribute), false);
If (optionCollectionAttributes!=null & amp; & OptionCollectionAttributes. Length & gt; 0 & amp; &
OptionCollectionAttributes [0] is OptionCollectionAttribute)
{
OptionCollectionAttribute myAttribute=optionCollectionAttributes [0] as OptionCollectionAttribute;
Return new StandardValuesCollection (myAttribute OptionCollection);
}
The else
{
Return to base. GetStandardValues (context);
}
}
}
Tie is a fixed value of two string, use the top of the converter
[TypeConverter (typeof (OptionValuesTypeConvertor)))
[OptionCollection (" regular, Hitachi cup ")]
, and use it every time you put these two properties assigned to a variable to the
And I don't know why, GetStandardValuesExclusive method whether assignment of true or false, don't check the value of the input is correct
CodePudding user response:
Use your code to try, there will be no ah, you are what type of variable, the string?CodePudding user response:
Right, is a string, but I this phenomenon is the ability to change and do not check