Jump to content

Setting the key focus on an array control programatically


Recommended Posts

I am trying (and failing) to set the key focus to the first element of an array control.  I want my dialog window to appear and have the cursor placed in the first element of a specific array control so the user can just start typing without first having to click on the element in the array.

This seems like it would be a simple things to do, so I am hoping that I am just making some bonehead mistake.

I have tried setting key focus, array element key focus, selection start and selection size.  None have worked.

 

Anyone know if this is possible?

 

I have attached an example VI with my attempts.

array key focus.vi

 

thanks for any wisdom...

 

-John

Link to comment

Thanks Darren.  Didn't know you have to get a property node for the string in the array.  I figured that the Array Element.Key Focus would be the same thing.

BTW: the panel activation is not needed, apparently.  I got it to work without it.

One issue: it seems to put the focus on the last element you clicked in before running the VI.  So, if you click in element 3 while in edit mode, then end text entry without typing anything, when you run the VI, the third element will have the cursor in it.

Is there any way to control which element in the array gets the key focus?

 

And is any of this documented anywhere?  (the bit about getting the ref to the element control)

Edited by John Lokanis
Link to comment

Ok, tried this in my actual application.  Didn't work.  Might be because my application has this VI as a floating window.  Or might be some other effect.

I tried making the example VI floating as well and found the sometimes the key focus did not work.  Seems to be flaky.

Does it matter if I set this from a sub-vi by passing in the ref to the string element of the array?

Also, does it matter if I initialize the array with empty strings after I set the key focus?

Link to comment

I am not seeing a way to get the key focus to always go to the first element (as opposed to going to the last one that was clicked).

 

I'm also not aware of any documentation on these particular array idiosyncrasies.

 

You need the panel activation if you're running the VI from somewhere other than the panel. For example, if you're on the diagram and you press Ctrl-R, the key focus doesn't take.

Link to comment
  • 1 year later...

Hi there,

The only way I found out is to set the value of the index and then the key focus. The problem that remain is that the first element show is the index value... For a GUI that you fix the size of the array, it could be confusing for the user.

 

Benoit

Link to comment

There is a PITA way of getting what you want.

Set the Array index to the element you want to set focus to.  Set the visible size of the Array to a single element (The one you want to set).  Set the focus. Set the size of the array back to the original settings.  Re-set the Index of the Array (if required).

Like I said, PITA.  By forcing the array to show only a single element, the control reference to the array element will be forced to the one you want.  I haven't tried doing this in advance and then using several array element references, but I think they will all change in unison (as the array element is a property of the Array).

Link to comment
  • 1 year later...

I couldn't make that work that way either...  It is possible something changed in LabVIEW since I used this trick.  It seems that setting the Index Value on the array makes focus go away.  And setting the KeyFocus any other time just sets the first element...darn.

But one method that does still work (and sucks even more) is you can navigate using various key combinations and you can simulate key presses to get the desired result.  So set KeyFocus to the string control.  This sets the focus on string control in the first index of the array.  Now if you press CTRL+Shift+Up Arrow, and your focus will be on the cluster element at index 0.  Now press Tab and it will be on the second cluster element.  Now press CTRL+Shift+Down Arrow and your focus will be on the second string control.  If you pressed tab twice it would be the third.  So you can programatically set the string control focus you want, but there is several complications with this method.  If you aren't looking at index 0 you need to do additional math to figure out what the index value should be, and how many times a tab is needed.  If I get some time today I'll try to post an example VI.  Mondays after a trip are always crazy

Link to comment

Dang so I can't even get this to work at the moment.  Using a physical keyboard CTRL+Shift+Up and Down does what I'd expect.  But the Keyboard Event code I have for some reason isn't doing what it should.  CTRL, and Shift seem to be working, or at least my on screen keyboard shoes them being activated when they should.  And the Up and Down appear to work as it goes up and down a line of text.  But when I put it in my application, it just doesn't do what I'd expect.  This is also with a whole bunch of waits added in case windows doesn't like fast key presses all the time.  I know I used this technique before but I can't seem to find the code that I used.

Link to comment
  • 1 year later...

Benoit: I just saw this post while hunting around for a bit of help myself. I looked at your VI. It's not a bug. You aren't ever setting the active element of the array -- the same physical position remains active unless you click with the mouse or use TAB key to move to the next element. To the best of my knowledge, there is no programmatic way to set the active physical slot of the array control other than simulating a mouse click or something exotic like that.

The array control is not a particularly good control for UI, in case you hadn't noticed. It was never designed for a interactive front panel. The one in NXG is better.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.