Select whole contents of a field when receiving focus

I have a form with a table control with a Date(Time) column. Whenever that field receives focus, the cursor is before all the contents, so the user has to manually highlight the contents to overwrite the default. What I want is for all the contents to be highlighted. I’m afraid the only approach to this will be to create a macro executed by the receiving focus event, and I’m not sure what that macro should look like. Any help would be appreciated.

Ctrl+A selects all the content.
You can also replace the date control with a formatted field with date formatting. This behaves more or less like a spreadsheet cell and selects the whole value on focus.

@Villeroy

Ctrl+A works well but formatted field does not select anything in:

Version: 7.2.0.1 / LibreOffice Community
Build ID: 32efc3b7f3a71cfa6a7fa3f6c208333df48656cc
CPU threads: 8; OS: Linux 5.4; UI render: default; VCL: gtk3
Locale: en-US (en_US.UTF-8); UI: en-US
Calc: threaded

Has been erratic in some past versions.

Hello,

In the properties of the control on the General tab, there is Hide Selection. If this is set to Yes, then when tabbed to, the entire field will be selected. This does nothing if the mouse is clicked in the field.

Perfect! That’s exactly what I needed. Keyboard navigation is better than mouse navigation, anyways.

I should have checked it out, first. It was already set to “Yes”, but it’s not highlighting the whole contents. I’m in LO 7.0.6.2

Unfortunately I failed to look close enough at your question - it stated a table control. There are open issues with this control. The test I did was with individual controls and this works. It does appear you may need a macro which I don’t have.

I agree with the nuisance to mouse select the date while in the flow of entering data. It took a while but this solves the issue.
Its best to attach the routine to the event ‘lost focus’ of the column preceding the date column, instead of ‘receive focus’ of the date column. This gives issues of recurrent execution of the routine, also after entering new digits.

May I suggest to edit the question to: ‘select (part) of contents of a field/column in a tablecontrol when receiving focus’

Sub selectPartOfDate(oEvent):

Dim oDoc,oForm,oDocCtl,oGrid,oControlView As Object
Dim iColumn As integer
Dim oSelection As New com.sun.star.awt.Selection 

oDoc = thiscomponent
oForm = oDoc.getDrawPage().getForms().getByName("MainForm")

oDocCtl = oDoc.getCurrentController()
oGrid = oForm.getByName("MainForm_Grid")

oControlView = oDocCtl.getControl(oGrid)
iColumn = oControlView.currentColumnPosition  'appears to be already the new landed (date) column

oSelection.Min = 0
oSelection.Max = 2
oControlView.getByIndex(iColumn).setSelection(oSelection)

End sub

Thanks! Unfortunately, I don’t see where I can edit the original question or the title…

Your macro got me there. I knew enough to make sure “MainForm” and “MainForm_Grid” matched the names used in my form. But then, it only highlighted the first 2 characters in the time field. I switched oSelection.Max to 5, and it started highlighting the entire time.

Unfortunately, upon upgrading to LO 7.1.5.2, this stopped working. I made sure that the event the previous column losing focus was still pointed at this macro. But it still puts the cursor at the begginning of the column contents.

sorry I can’t be of any help I’m using LO 6.5 and find it too much effort to install the stated version in parallel. There is also the remark of Ratslinger that ‘there are issues with this control’.
Is yes/no hide selection now working in this version?

Thanks! I rolled back to LO7.0.6.2, and it started working again.
And no, the “Hide Selection” for date controls is still not working for the newer LO version (7.1.5.2).