Click here to Skip to main content
15,889,874 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
How limit the length of the input string in winform PropertyGrid? If length of the input string eyond the fixed length,beyond the part is not displayed! Thank you for your help!
Posted
Comments
Sergey Alexandrovich Kryukov 1-Jul-15 12:11pm    
Not displayed or not actually entered in data?
—SA
Lee Yuan 1-Jul-15 23:06pm    
not actually entered in data.
Sergey Alexandrovich Kryukov 2-Jul-15 1:09am    
Please see my solution.
—SA

1 solution

This is a big and difficult topic, but resulting implementation can relatively simple; it's only hard to explain.

Please see my comment to the question. The right idea is: you can simply cut too long line, or throw the exception suggesting to the user to choose shorter string. Of course, all exceptions should be handled in the main UI event loop, so the user will be able to see the error message and continue working with the UI, correcting the input. Such exception handling is a must; I described it in my past answers:
Catching an Exception[^],
Error Logging and Screen Shot.[^],
When i run an application an exception is caught how to handle this?[^],
Keep a c# windows form application running despite any unhandled exception[^],
How do i make a loop that will stop when a scrollbar reaches the bottom[^],
Handling exceptions in class library (dll)[^],
Exception Details: System.Runtime.InteropServices.COMException: Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error:...[^].

Sorry, there are a lot of repetitions in my advice on exception, but better read it all.

But now, how to modify the behavior of the PropertyGrid? This particular case is relatively easy: you can write and apply custom User Interface Type Editor. You can start here:
https://msdn.microsoft.com/en-us/library/37899azc.aspx[^],
https://msdn.microsoft.com/en-us/library/ms171838.aspx[^].

The idea is: you design, implement and apply some custom editor for your type and apply EditorAttribute with your editor type to your type which should be edited under the PropertyGrid:
https://msdn.microsoft.com/en-us/library/ms171840.aspx[^].

Essentially, you achieve desired effect (cutting the string on the fly or throwing exception) in your implementation of the method EditValue.

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900