In my project I have a grid cell bound to a data point that has a fixed allowable length (36 chars)
There is a routine in the program that attempts to "Auto Build" this data however sometimes due to the other inputs the results is greater than 36 chars.
The user can then make manual corrections to the point to shorten it
What I wanted to be able to do was provide a quick reference point to show when the string was with-in the accepted length.
My first attempt was using a .MaskInput = ">&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&|" but I forgot that this would still truncate the excess string (Duh!)
I was unable to find anything that would just allow "anything" after the pipe regardless of length so I just added 25 more '&' after the pipe character to allow for some excess data - this is 'OK' and will likely be enough space but it causes Column width issues (grid thinks the column should be wide enough to accommodate the full mask even when there's no data) and when the cell enters edit mode for the user to make corrections the MaskInput makes the cell / string act like there are padded white spaces on the end instead of going to the last visible character as one would expect.
Is there some format string character or MaskInput option that I'm missing that will allow for a non-fixed length of trailing characters after the pipe or is there a different / better way to tackle this problem than using an Input Mask?
Thanks in advance for your help.
Stephen
Edit - the allowable length is constrained in the database on the back end and I handle trimming the data prior to save. I have not constrained the column in any way (i.e. maxlength) so as to allow the display of the auto generated data
Hi Steve,
Presumably, you want the indicator to appear only while the user is editing the cell. Is that right? I mean, leaving the cell with data that is too long is completely out of the question, since this will force the data to be saved to the data source, which cannot handle it and will raise an exception. So this only makes sense while the caret is in the cell during editing.
I don't see any way to do this using masking.
I've seen some web site where they have a text box with a limited character input and what they do is they display some text outside of the textbox with a running total of the current number of characters. So maybe you could put up a tooltip or a label somewhere next to the grid that says something like:
"Maximum Characters Allowed: 100"
"Current length: 105"
Then you update the label using the TextChanged event so the current length is updated as the user types.
Another option would be to use color. You could set the ForeColor on the cell.Appearance to Red, for example, while the text is too long. Again, you would use CellChange for this and as soon as the text is short enough, you would revert to the normal cell color. The down side of this approach is that it may not be immediately obvious to the user why the text is red.
Another possible solution would be to use the UltraValidator component. I'm not sure, but I think it has the ability to enforce a length constraint, change the text color and also display an error icon which can display a tooltip with more detailed error information. It's been a while since I used it, though, so I might be overestimating it's capabilities.
Dave,
Thanks for the fast response.
The forums threw an error when I posted my edit, so I had to try and edit my post a second time and apparently I omitted the fact that I am using a fixed width font that time around.
Anyhow - in that case character width is the same and therefore not really a hurdle. Also this is an "in house" application so I have total control over the font used and size and don't have to worry about someone else changing them.
This could allow for a "low tech" solution like a background image in the cell but it is not ideal and I would not like to go that route if at all possible.
I have used your solution in one of the predecessors to this application and it was not very well received and dropped altogether in the currently active version.
For the small percentage of time they will actually have to edit the data this may just be something they have to live with or maybe I can do something with the text length and selection start properties on edit of the cell. I'll keep digging, just wondered if anyone else had crossed this bridge or had a better solution.
Thanks Again
Steve
Hello Stephen,
Thank you for contacting Infragistics.
It's not really possible to display an indicator inside the cell since different characters can be different widths. What I would suggest is using a label or status bar outside of the grid to display the current length of the text in the cell. You would get this length by handling the CellChange event of the grid and accessing e.Cell.Text.Length inside the event handler.