Windows Develop Bookmark and Share   
 index > Windows Forms General > Textbox control maxlength 70, yet can paste strings longer than 70 chars?
 

Textbox control maxlength 70, yet can paste strings longer than 70 chars?

Hi everyone,

I've run into an interesting issue.

I have a single-line custom textbox control on a form. It's multiline property is set to false, and the maxlength is set to 70.

I override the WndProc method within the control on a WM_PASTE message, and call a custom DoPaste message to paste in text from the clipboard.

The text in the clipboard we want to paste (just a string) is 130+ characters.

When we do the following:

((

TextBox)ctrl).Paste(clipboardText);

it pastes the full length of the text in the textbox. The control is databound to a database field with a limit of 70 characters, so even though we see the full length of the text in the textbox, it's not saved in the database.

We haven't modified any other properties of the textbox so it's all still the same as the base text box.

My question is, even though it's a custom control, since the maxlength of the textbox is set to 70, shouldn't it automatically be truncating the string to 70 characters when pasted in the control regardless of what I do in a custom paste method? Or does programmatically doing the pasting supposed to automatically (apparently) override the control's maxlength property?

Thanks!
FireMyst  Tuesday, September 22, 2009 1:24 AM
In the help system, it says this:

"In code, you can set the value of the Text property to a value that has a length greater than the value specified by the MaxLength property. This property only affects text entered into the control at run time."

I wonder if text entered using this code is not viewed as being entered at runtime?

Hope this helps.
www.insteptech.com ; msmvps.com/blogs/deborahk
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
  • Marked As Answer byFireMyst Tuesday, September 22, 2009 3:17 AM
  •  
DeborahK  Tuesday, September 22, 2009 3:09 AM
In the help system, it says this:

"In code, you can set the value of the Text property to a value that has a length greater than the value specified by the MaxLength property. This property only affects text entered into the control at run time."

I wonder if text entered using this code is not viewed as being entered at runtime?

Hope this helps.
www.insteptech.com ; msmvps.com/blogs/deborahk
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS!
  • Marked As Answer byFireMyst Tuesday, September 22, 2009 3:17 AM
  •  
DeborahK  Tuesday, September 22, 2009 3:09 AM
Awesome. Thanks for that.

Certainly explains why things are happening the way they are.

Seems strange though that this property (I'm sure there are others as well) is ignored when doing things programmatically. But, on the flip side, I can also see why as well.

FireMyst  Tuesday, September 22, 2009 3:19 AM

You can use google to search for other answers

Custom Search

More Threads

• multilingual software in vb.net.
• Cannot Access File
• How can I extract data from a Java applet from VB.Net?
• Open a file that is already opened by another app in readonly mode
• Single Instance MDI Application with multiple MDI Child Not Working
• User Account Resolutions in Vista
• Combobox not displaying data correctly
• TreeView duplicating nodes in Internet Explorer
• Multithreaded application behaving abnormal.
• Display sort mode icon in datagridview