2017-04-02 1 views
0

私はそのSystem.ArgumentExceptionの:「プロパティにバインドすることはできません 『バリュー』目標管理上の

public class EditDateTimeBox : UserControl,IKeyboardNavigation 
{ 

    private TextBox textBox; 

    private MonthCalendar monthCalendar = new MonthCalendar(); 
    ToolStripDropDown popup = new ToolStripDropDown(); 
    ToolStripControlHost host; 
    //..... 
    [Bindable(true)] 
    public DateTime Value{get;set;} 
} 

様結合が、私はそのようにそれをバインドしようwheneサポートするいくつかのプロパティを持つ光のUserControlを開発しています:

bool _binded = false; 
    string _dataColumn ; 
    [Category("OverB")] 
    [Browsable(true)] 
    public string DataColumn 
    { 
     get 
     { 
      return _dataColumn; 

     } 
     set 
     { 
      _dataColumn = value; 
      if (!_binded && !string.IsNullOrEmpty(_dataColumn) && _dataSource != null) 
      { 
       this.DataBindings.Add("Value", DataSource, _dataColumn,true); 
       _binded = true; 
      } 
     } 
    } 

スローされたエラーは言う: System.ArgumentExceptionのは:対象のコントロール

私のデバッグに値 『「プロパティにバインドすることはできません』 DOTNETのサポートで、私はChechBinding()メソッドではBindingクラス(のSystem.Windows.Forms)がここで問題 を引き起こすことがわかったコメント

// If the control is being inherited, then get the properties for 
      // the control's type rather than for the control itself. Getting 
      // properties for the control will merge the control's properties with 
      // those of its designer. Normally we want that, but for 
      // inherited controls we don't because an inherited control should 
      // "act" like a runtime control. 
      // 
      InheritanceAttribute attr = (InheritanceAttribute)TypeDescriptor.GetAttributes(control)[typeof(InheritanceAttribute)]; 
      if (attr != null && attr.InheritanceLevel != InheritanceLevel.NotInherited) { 
       propInfos = TypeDescriptor.GetProperties(controlClass); 
      } 
      else { 
       propInfos = TypeDescriptor.GetProperties(control); 
      } 

      for (int i = 0; i < propInfos.Count; i++) { 
       if(tempPropInfo==null && String.Equals (propInfos[i].Name, propertyName, StringComparison.OrdinalIgnoreCase)) { 
        tempPropInfo = propInfos[i]; 
        if (tempPropIsNullInfo != null) 
         break; 
       } 
       if(tempPropIsNullInfo == null && String.Equals (propInfos[i].Name, propertyNameIsNull, StringComparison.OrdinalIgnoreCase)) { 
        tempPropIsNullInfo = propInfos[i]; 
        if (tempPropInfo != null) 
         break; 
       } 
      } 

      if (tempPropInfo == null) { 
       throw new ArgumentException(SR.GetString(SR.ListBindingBindProperty, propertyName), "PropertyName"); 

でコードが任意のアイデアですか?エラーがpurly鉱山である

+0

申し訳ありませんが、IBindableComponentに私のコントロールからいくつかの鋳造があり、このような理由のために、私の新しいプロパティがそれは...プライベートIBindableComponent制御を存在dosn't!。 propInfos = TypeDescriptor.GetProperties(コントロール);何か案が!!!! –

答えて

0

申し訳ありませんが、私は問題を発見し、ここでゾンビーコードが

公共新しいControlBindingsCollectionのデータ連結は、{{戻りtextBox.DataBindingsを取得することです。 }}

方法(DOTNET)CheckBinding()で

関連する問題