[SOLVED] Databinding and ToolTip

Answered
0
0

Hi,

I think databinding and tooltip is not working.

I have added the ToolTip control to the form. On a textbox in databinding properties I have bound the ToolTip to a text field in my bindingsource. When i run the program I get an error message:

Cannot bind to the property ‘ToolTip’ on the target control.
Parameter name: PropertyName

 

Best regards,

Wilfred

  • You must to post comments
Best Answer
0
0

Controls don’t have a “ToolTip” property. You see it in the designer because of the ToolTip component which is a property extender (System.ComponentModel.IExtenderProvider). It’s similar to the other extenders we have: Bubbles, Animation, StyleSheet, all panels, etc. These components add properties to other controls at design time.

At runtime you can set those properties using the component:

this.toolTip.SetToolTip(this.button, “Test”);

For data binding you need an actual property. You could add a property string ToolTip { get; set; } and in the setter get the form using FindForm(), get the tooltip extender and set the value. Another way is to extend the wisej controls like the sample attached and code below:

 

public class MyButton : Button
{
  [DefaultValue(null)]
  public string ToolTip
    {
      get { return this._toolTip; }
      set
      {
        if (this._toolTip != value)
        {
          this._toolTip = value;
          Update();
        } 
     }
   }
   private string _toolTip;

   protected override void OnWebRender(dynamic config)
   {
     base.OnWebRender((object)config);
     config.toolTipText = this.ToolTip;
   }
}

 

  • Wilfred Schønegge
    Yes, I know the ToolTip component is an extender that adds the property ToolTip. The advantage of using this extender is that it will add the property ToolTip to all types of controls you drop to the form. Or at least that is how I think is should work. But when i bind to that property, the ToolTip property that is added by the extender, I get the error message.. What do you think?
  • Luca (ITG)
    Without a property the data binding cannot work. The “ToolTip” property you see in the designer is an extender’s property, it’s not a real property. See the attached code sample on how to make it become a real property. Properties added by the extender are not properties, they just appear to be properties to the designer.
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.