2012-03-20 56 views
6

我有一個System.Windows.Forms.PropertyGrid與不同類型的值。對於特定項目,我想顯示有用值的列表以供選擇。用戶也可以輸入新的值。一些類似於傳統的下拉組合框:如何將可編輯的組合框添加到System.Windows.Forms.PropertyGrid?

enter image description here

到目前爲止,我有我自己的System.ComponentModel.TypeConverter,但我無法弄清楚如何與建議值編輯的可能性同時獲得下拉直接值。請幫忙!

回答

4

很簡單。在你自己的StringConverter返回falseGetStandardValuesExclusive就是這樣。

看看這裏:

internal class cmbKutoviNagiba : StringConverter 
{ 
     public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) 
     { 
      return FALSE; // <----- just highlight! remember to write it lowecase 
     } 

     public override TypeConverter.StandardValuesCollection GetStandardValues(
      ITypeDescriptorContext context) 
     { 
      string[] a = { "0", "15", "30", "45", "60", "75", "90" }; 
      return new StandardValuesCollection(a); 
     } 

     public override bool GetStandardValuesSupported(ITypeDescriptorContext context) 
     { 
      return true; 
     } 
    } 

我用大寫字母寫道FALSE,只是爲了讓你easyer看到它。請用小寫字母:)

+1

順便說一下:'GetStandardValuesExclusive'的覆蓋似乎只有在從'StringConverter'派生的類中使用時纔會被調用。當你從'TypeConverter'派生你的類時,它似乎不會被調用。 – 2014-12-19 10:45:44