Mouse click on a listbox cell

How can I reproduce with code a mouse click on a listbox cell?

It depends on the cell. If the cell isn’t user editable (has no text field when you click on it), clicking a cell will select the row.

Case 1 (the cell isn’t editable):
If your listbox doesn’t have the multi selection mode, just use this in the CellPressed event:

Return true

If your listbox allows multi selection, you’ll have to handle when the user holds the command key (on Mac) or control (on Windows/Linux) or shift key.

With the command/control key, the row should be added (or removed) to/from the existing selection, like this (in the same event):

me.RowSelectedAt(row)=not me.RowSelectedAt
Return True

With the shift key, the selection would expand up to the selected row. For this, you’d have to store the last time there was a single selected row (store its index), and select all rows between the first selected row and the current selected one. It’s even trickier if the user has selected more rows with command/control clicks in between. Reproducing the OS behaviour is going to take time here.

Case 2: the cell is editable.
If the cell has a checkbox, put this (again in the CellPressed event):

me.CellCheckBoxValueAt(row,column)=not me.CellCheckBoxValueAt(row,column)
Return True

If the user can enter text, put this instead:

Return True

As you can see, if your listbox allows multiple selection, what you asked is rather complex to reproduce how the OS works (and each OS may work slightly differently). It’s usually better to let the OS do the task for better user experience.

Thanks Arnaud. The idea is to press (mouse click) with code one cell when its text matches with one textfield.text. which of your choices is the right one? Thank you very much

So you want to highlight the cell matching the text field, right?
If true, both of my answers aren’t on topic (mouse clicking and displaying are separate things).

Let’s assume the cell to highlight is in the 2nd column and 5th row (we start with an example where the cell is static). Add a PaintCellBackground event to the listbox, with this code:

if row=4 and column=1 then
  g.DrawingColor=New ColorGroup("selectedContentBackgroundColor")
  g.FillRectangle 0,0,g.Width,g.Height
  Return True
end if

And the PaintCellTag could look that way:

if row=4 and column=1 then
  g.DrawText me.CellTextAt(row,column),x,y
  Return True
end if

Then, you would store in properties the last clicked row and column (in the CellPressed event) so your code can dynamically handle the proper cell.

Or are you looking for something else?