Convert vb6 Selection Code

Kelly Martens
Kelly Martens used Ask the Experts™
on
In vb6 this will select the text of two textboxes.

Public Sub SelectEntireText(txt_box As TextBox)

    txt_box.SelStart = 0
    txt_box.SelLength = Len(txt_box.Text)

End Sub

In C# I need to do the same but with a datetimepicker control. (The text representation of the date). How could I do this?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Chinmay PatelChief Technology Ninja
Distinguished Expert 2018

Commented:
Hi Kelly,

I am not sure if it is the same with DateTimePicker. I would like to know what exactly you are trying to do after selecting the text?

Please refer to: https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.datetimepicker.text?view=netframework-4.7.2

Regards,
Chinmay.
Éric MoreauSenior .Net Consultant
Top Expert 2016

Commented:
Isn't there a .Select() method you can call on the DTP control?
Éric MoreauSenior .Net Consultant
Top Expert 2016

Commented:
I just tried and the .Select() method does not have the expected behavior.

This is surely because the DTP control has been overloaded to react to the up and down arrows to change the selected part (which is highlighted).
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
Right I found that too. I'm trying to mimic what the textboxes are doing because boss wants the same results for enduser

Author

Commented:
Chinmay its just a visual effect of selection bias is after here
Éric MoreauSenior .Net Consultant
Top Expert 2016

Commented:
but doesn't really make sense because when you are working with a textbox you are working with only one of its parts at a single time.
Chinmay PatelChief Technology Ninja
Distinguished Expert 2018

Commented:
Hi Kelly,

I think I can do some research in the area - but trust me - I do not have a good feeling about it. If that does not work out, are you Ok with a custom control?

PS: I love to do hac-n-slash solution, heck my entire career is built around those but this one :P...  I don't think I would recommend you or anyone to go through it.

Regards,
Chinmay.
Chief Technology Ninja
Distinguished Expert 2018
Commented:
Hi Kelly,

DateTimePicker is an ActiveX control which has many other sub controls wrapped inside a container. I would not want to dive further in this.
If you want to do it, you might be able to do it via reflection.

If your boss does not agree then only way out is for you to make a UserControl which can provide the behavior you need or come up with other visual hacks, for example, hide the entire control, show a textbox and set its Text property to what user has selected in DateTimePicker and then select that text. If it was just to copy text on the clipboard you can easily get the values by using Text or Value property of DateTimePicker.

Regards,
Chinmay.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial