04-12-2016 09:46 AM
Hello Community,
I am trying to limit the string character size of an edited cell.
I understand how to limit the size of one string, but I have never done it with a table before.
Is there a way to limit the character size of the one cell being edited?
It can either return the substring or revert back to the original content in the string, then prompt the user with a message.
Solved! Go to Solution.
04-12-2016 11:18 AM
You'll need two events for the table. The first event will check for Key Down. Inside this case, use the Edit Position property node to store the location of the text edit. In the second event (Value Change), use the stored position to get the string subset and write it back to the table. This could be done using the In-Place element structure. This method will allow the length to exceed your parameter while the user is typing but will truncate the data on undate of the table.
This could potentially be done with one event where any characters over the specified length just simply don't appear. However, i haven't tried it out yet.
04-12-2016 11:45 AM
Unless there are some new table methods in 2015, I'm not seeing an easy way of limiting string length while the user types. The problem is that tables don't seem to update their value while typing. The text is store in some buffer and then updated when the user presses enter or clicks out of the cell. So in order to do it this way, you would have to maintain an array of characters as the user types and discard any over the specified length, which is easy enough to do but then you would need another event to detect when to clear out the array for the next cell edit. Doesn't seem like a clean solution to me.
Again, I'm not using the latest version so there may be improvements to this that I'm not aware of.
04-12-2016 11:53 AM
So it's ugly but a solution might be to make the UI look like a table, but really it is just a string control that is moved and sized to look like a cell that the user clicked.
I've seen similar techniques to put drop downs in a table like here. Then this string control can have the update while typing option, and a key down can be triggered for each press. Or you might get away with using this XControl made a while ago which also limits string length.
But long term, I think having the update while typing be an option for a table would be a good idea, maybe you should add this to the idea exchange.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
04-12-2016 12:02 PM
I was looking at that possibility when I saw your comment come in, Hoovah. You could have one string control that is hidden but is made visible, moved, resized to the active cell, then set as the Focus Object. After finishing string input and limiting string length (discarding characters), hide the string control and update the active cell in the table. WOW. Good luck with that.
04-12-2016 12:32 PM
I've done crazier things in the name of having a good UX in LabVIEW. But yeah I don't want to.
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
04-12-2016 01:13 PM
@aputman wrote:I was looking at that possibility when I saw your comment come in, Hoovah. You could have one string control that is hidden but is made visible, moved, resized to the active cell, then set as the Focus Object. After finishing string input and limiting string length (discarding characters), hide the string control and update the active cell in the table. WOW. Good luck with that.
If you look at the code I provided in the thread that Hooovahh linked, it wouldn't be difficult to modify it to do this.
04-12-2016 01:34 PM - edited 04-12-2016 01:35 PM
@nathand wrote:If you look at the code I provided in the thread that Hooovahh linked, it wouldn't be difficult to modify it to do this.
BTW I did start wrapping that functionality into an XControl with support for colorbox selection, boolean, enums, combo boxes, numerics, and strings all defined by a provided cluster that the XControl then looked at the individual elements for. I got decently far but lost interest. It didn't have a function like limiting string length or input, but it did have disabled cells, rows, columns, auto sizing columns, sorting by header clicking, navigation with tab and return keys, reordering with drag and drop, I never quite was happy with the drag and drop from other controls, and a few other half finished ideas. As is the case with most XControls the effort put into them can be large, especially when the requirements grow. Oh and so many work arounds...
Unofficial Forum Rules and Guidelines
Get going with G! - LabVIEW Wiki.
17 Part Blog on Automotive CAN bus. - Hooovahh - LabVIEW Overlord
04-12-2016 02:36 PM
Aputman,
If not too difficult, would you be able to create a simple example vi using the 2 events for the table?
04-12-2016 02:57 PM - edited 04-12-2016 03:02 PM
It was already done.
Edit: Ignore my bad coding practice for not stopping the loop properly. It's sample code.