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