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
Dave & Mike,
Thank you both for all your help & guidance. I really do appreciate what you guys do to make this one of the best support forums on the net.
Dave
I really like what you did and can/will incorporate that into other areas of this project, but for this specific issue it's just not as good a fit as what I am doing above.
In all fairness to you - there are other criteria involved (good old feature creep) that I did not include in the initial question because I was hoping it was a simpler solution and didn't want to cloud the issue with any more constraints that I had to. What you provided did in fact cover what I *asked* for just not what I really *needed*
Therefore I have marked both your and my solutions as answers for any possible future readers
Thanks again for your help.
Hello,
Thank you for your response.
Please let me know if I can be of further assistance.
Thanks Dave
I'll look at that and see if it's a better fit that all the hoops I'm jumping through above.
Hi Mike,
Thanks for the suggestions.
I am still testing but I think I have a workable solution.
I used some of the information here ( http://stackoverflow.com/questions/17042149/format-ultragridrow-cells ) coupled with the source code of the WinGrid Sample Explorer section referenced in that link to create a custom editor for each cell only if it exceeds the max length
How it works is; during the InitializeRow event I'm calling a Read Only Property from my custom Defaults Class that builds a custom mask for each entry this way I don't have extra trailing spaces in the mask. If the length of data for the field in that row is within the required length the routine returns Nothing otherwise it returns a '&' for every character of allowed length, a Pipe, and a '&' for every character above the allowed length in the length of the string.
Public Shared ReadOnly Property mask_ExtendedName(point As _IPoint) As String Get If point.ExtendedName Is Nothing OrElse point.ExtendedName.Trim.Length <= length_ExtendedName Then Return Nothing Else ' Start with the Upper Case all Character Dim tmpstr As String = ">" ' Add placeholder for every position in allowed length For x As Integer = 1 To length_ExtendedName tmpstr = tmpstr & "&" Next x ' Add Pipe character tmpstr = tmpstr & "|" ' Add placeholder for every extra character For x As Integer = length_ExtendedName + 1 To point.ExtendedName.Trim.Length tmpstr = tmpstr & "&" Next x Return tmpstr End If End Get End Property
Next I test the results of that routine and if it's NOT nothing then I create a new EditorWithMask using the MaskInput string returned by my routine and set the cell editor to that new editor, otherwise nothing happens and it's business as usual for the grid.
Here's the snipit from the InitializeRow event
Dim _mask As String = DataLengths.Point.mask_ExtendedName(CType(e.Row.ListObject, _IPoint)) If _mask IsNot Nothing Then Dim editorSettings As New DefaultEditorOwnerSettings With editorSettings .MaskDataMode = UltraWinMaskedEdit.MaskMode.Raw .MaskDisplayMode = UltraWinMaskedEdit.MaskMode.IncludeBoth .MaskInput = _mask End With e.Row.Cells("ExtendedName").Editor = New EditorWithMask(New DefaultEditorOwner(editorSettings)) End If
I am already using background color change to indicate what cell(s) have errors and my Save routine will trim the data to the max allowed length to prevent SQL based exceptions.
And to answer your first question, it would not be a deal breaker if the Pipe was visible all the time as it would give an indicator of how much free space was left. This current solution works as you describe, showing only the Pipe character when the cell is actually in edit mode, It might actually be nice to have it show all the time once it's set on the values in error because the user then knows how much they have exceeded it limit by without having to click into the cell.
Thanks again for all the help.
Hello Steve,
Here is a sample project demonstrating using the UltraValidator to let the user know when they've entered too many characters.
Please let me know if you have any other questions about this.