2016-04-01 19 views
3

Bu kodu internet kaynağından aldım, bu kodun özellik özelliğini PropertyGrid'de metin kutusundan açılan kutuya dönüştürmek için iyi çalıştığını düşündüm, ancak bunu çalıştırdıktan sonra, yine de bir metin kutusu. Bunu çözmek için herhangi biri yardımcı olabilir mi?propertygrid özelliklerinde combobox özelliğini değiştirin

public class Testing 
{ 

    private String _formatString; 
    [Category("Display")] 
    [DisplayName("Format String")] 
    [Description("Format string governing display of data values.")] 
    [DefaultValue("")] 
    [TypeConverter(typeof(FormatStringConverter))] 
    public String FormatString { get; set; } 

    public class FormatStringConverter : StringConverter 
    { 
     List<String> list = new List<String>(); 

     public override bool GetStandardValuesSupported(ITypeDescriptorContext context) { return true; } // true means show combobox 
     public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) { return true; } // true list to list, false will show the list, but allow free=form. 
     public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) 
     { 

      list.Add("Curren"); 
      list.Add("Currency"); 
      list.Add("Scientific Notation"); 
      list.Add("General Number"); 
      list.Add("Number"); 
      list.Add("Percent"); 
      list.Add("Time"); 
      list.Add("Date"); 



      return new StandardValuesCollection(list); 
     } 
    } 
} 

cevap

0

Özellik değerini TextBox'tan ComboBox'a göstermemiz gerekirse, belirli özellik tipi için özel düzenleyici yazmak istiyoruz. ComboBox'taki (String dizi türü olan) özellik değerini göstermek için aşağıdaki kod parçacığını bulabilirsiniz

 public class ComboBoxEditor : ITypeEditor 
    { 
     public void Attach(PropertyViewItem property, PropertyItem info) 
     { 

     } 

     ComboBoxAdv cmb; 
     public object Create(PropertyInfo propertyInfo) 
     { 
      cmb = new ComboBoxAdv(); 
      cmb.Items.Add("Curren"); 
      cmb.Items.Add("Currency"); 
      cmb.Items.Add("Scientific Notation"); 
      cmb.Items.Add("General Number"); 
      cmb.Items.Add("Number"); 
      cmb.Items.Add("Percent"); 
      cmb.Items.Add("Time"); 
      cmb.Items.Add("Date"); 
      return cmb; 
     } 

     public void Detach(PropertyViewItem property) 
     { 
      throw new NotImplementedException(); 
     } 

} 

CustomEditor ComboBoxEditor = new CustomEditor() { HasPropertyType = true, PropertyType = typeof(string[]) }; 
     ComboBoxEditor.Editor = new ComboBoxPropertyGridSample.ComboBoxEditor(); 

i de bu

http://www.syncfusion.com/downloads/support/directtrac/general/ze/ComboBoxPropertyGridSample1192877556

basit örnek eklenmiş