PDM add-in task text box

Installation, PDM, standards, training, support, part numbering, rev schemes, etc.
MMartens
Posts: 30
Joined: Wed Apr 28, 2021 10:01 am
Answers: 5
Location: Shawano, WI USA
x 6

PDM add-in task text box

Unread post by MMartens »

I am developing an task addin for my users. On my custom task setup page I have a multiline text box that I plan to use to change the options available in a listbox on the launch task card. This would allow me to easily change the values available in the listbox without having to rewrite the code to change the listbox items.

The problem is when I am in task setup and I hit enter to create a new line in the textbox, the task setup control treats it as me hitting enter to click the OK button. The print task that comes with the Solidworks Task Add-in has a control that operates the way I would expect but I haven't been able to figure out the right combination of properties and programming to get what I need.
image.png
by MMartens » Wed May 31, 2023 8:25 am
I tried intercepting the keypress events but the enter button doesn't trigger the textbox keypress events before it closes the task setup. I'm thinking of converting this to a listbox with control buttons for adding or removing items from the list. It has the added benefit of having a sort property so I don't need to sort the list every time I enter a new line.
Go to full post
User avatar
AlexB
Posts: 434
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 22
x 242
x 383

Re: PDM add-in task text box

Unread post by AlexB »

I believe there is a property for TextBox controls called AcceptsReturn that you can set to allow it to create a new line when enter is pressed.

I believe this line should get you what you need.

Code: Select all

myTextBox.AcceptsReturn = true;
MMartens
Posts: 30
Joined: Wed Apr 28, 2021 10:01 am
Answers: 5
Location: Shawano, WI USA
x 6

Re: PDM add-in task text box

Unread post by MMartens »

That's what I initially thought but it doesn't work.
User avatar
AlexB
Posts: 434
Joined: Thu Mar 18, 2021 1:38 pm
Answers: 22
x 242
x 383

Re: PDM add-in task text box

Unread post by AlexB »

MMartens wrote: Tue May 30, 2023 3:07 pm That's what I initially thought but it doesn't work.
Okay, I played around with a task add-in and can replicate your issue. I even tried to intercept and cancel the keypress event and was not able to get it to do what you're looking for. Sorry :|
User avatar
AlexLachance
Posts: 1991
Joined: Thu Mar 11, 2021 8:14 am
Answers: 17
Location: Quebec
x 2155
x 1847

Re: PDM add-in task text box

Unread post by AlexLachance »

If it's replicable, might wanna hit up your VAR. Maybe they could cook up a temporary solution for you.
User avatar
bnemec
Posts: 1850
Joined: Tue Mar 09, 2021 9:22 am
Answers: 10
Location: Wisconsin USA
x 2435
x 1330

Re: PDM add-in task text box

Unread post by bnemec »

Try playing around with the tab stops (tab order) in your setup form controls? It looks like the "OK" button is still selected/active even though you're cursor is active in the textbox.

Alternatively, can you add hook to Key Down and/or Up events and swallow the event using KeyPressEventArgs.Handled Property = true; if it's the enter key to prevent the parent control from using it to "click" the ok button?
MMartens
Posts: 30
Joined: Wed Apr 28, 2021 10:01 am
Answers: 5
Location: Shawano, WI USA
x 6

Re: PDM add-in task text box

Unread post by MMartens »

I tried intercepting the keypress events but the enter button doesn't trigger the textbox keypress events before it closes the task setup. I'm thinking of converting this to a listbox with control buttons for adding or removing items from the list. It has the added benefit of having a sort property so I don't need to sort the list every time I enter a new line.
User avatar
JSculley
Posts: 575
Joined: Tue May 04, 2021 7:28 am
Answers: 53
x 7
x 807

Re: PDM add-in task text box

Unread post by JSculley »

Seems like a limitation. You can use an alternate approach by using a list and some buttons instead of a text box.
image.png
Another approach might be to look for the text box getting focus, and then store the value of the AcceptButton property of the parent Form in a variable and then set the value of the AcceptButton property of the parent Form to 'null'. When focus is lost on the textbox, set the value of the AcceptButton property of the parent Form to the stored variable.
Post Reply