User Control - Text propety

D

DS

I'm trying to create a user control in which I have a textbox , and I want
to be able to set the default value at design time in the Winforms designer,
but I'm running into a bit of a problem. The only items on the control is a
textbox and a listbox. First, here's the code:

[Description("Gets or sets the text contained in the control."),
Category("Appearance"),
Browsable(true)]
public override string Text
{
get
{ return txtQuery.Text; }
set
{ txtQuery.Text = value; }
}

If I have it like this, any forms that I've added to the control already
behave properly. If I try to add the control to a form though, I get this
cryptic error from VS.Net:
"Count cannot be less than zero. Parameter name: count"
No luck googling it either. Strangely though, if I remove the browsable
attribute, or rename the property to something like 'texta' then it works
just right. Problem with removing the browsable attribute is that then it
isn't displayed in the properties pane; if I name it 'texta', then its not
very consistant with the reast of the framework.

What am I doing wrong here, or have I had the pleasure of finding yet
another "undocumented feature"? Is there a way to make this work, or should
I just name it something else and be done with it?

Thanks
-Dan
 
D

Dmytro Lapshyn [MVP]

Hi,

I've found this passage in the MSDN documentation on the Control.Text
property, might be it can be helpful:

"Notes to Inheritors: When overriding the Text property in a derived class,
use the base class's Text property to extend the base implementation.
Otherwise, you must provide all the implementation. You are not required to
override both the get and set accessors of the Text property; you can
override only one if needed."

Also, this message thread might suggest something useful (mind the line
wraps):

http://groups-beta.google.com/group...osoft.public.dotnet.*&rnum=4#339046cc304bec24
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top