LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Limit Cell String Size

Solved!
Go to solution

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.

 

0 Kudos
Message 1 of 16
(4,592 Views)

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. 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
Message 2 of 16
(4,573 Views)

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. 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 3 of 16
(4,564 Views)

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.

0 Kudos
Message 4 of 16
(4,556 Views)

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.  Smiley Very Happy

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 5 of 16
(4,551 Views)

I've done crazier things in the name of having a good UX in LabVIEW.  But yeah I don't want to.

0 Kudos
Message 6 of 16
(4,542 Views)

@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.  Smiley Very Happy


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.

0 Kudos
Message 7 of 16
(4,516 Views)

@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...

0 Kudos
Message 8 of 16
(4,508 Views)

Aputman,

 

If not too difficult, would you be able to create a simple example vi using the 2 events for the table?

0 Kudos
Message 9 of 16
(4,491 Views)
Solution
Accepted by topic author MechUnit

It was already done.  Smiley Wink  

 

Edit: Ignore my bad coding practice for not stopping the loop properly.  It's sample code.  

 

Example_VI_BD.png

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
Message 10 of 16
(4,484 Views)