Fire CellClick event By code

Hi everyone
How can i simulate mouse click on first row of a listbox
i’v tried those 2 line …but they only select it

Listboxfilez.Selected(0)=True Listboxfilez.ListIndex = 0
I need to trigger the cellClick Event when the listbox finish loading data

you don’t

in the MouseDown event (or cellClick event) put


then in a public module, create a method called MyMouseClickCode

then to “simulate” the mouse click, just call that method, just like the Click event will be calling it

Attempting to interject mousetype events into the message stream is very bad practice

Thanks Dave
I’v take note of your advice of ( bad practice )
And i simply create a method with the same content of cellclick ( replacing “row” by 0 )
Even better… Cellclick only containing the row reference and send param to method
That’s best programming practice ?

yup… put the code in a central place… and call it from many places… passing whatever parameters are required.

Basically… keep the GUI and its events distinct from the logic…

In a well designed application, the Window/Form/View (whatever you might call it), should have minimal (ie. zero if possible) “business logic” in it,

and NOT same content… do not DUPLICATE the code, put it in ONE place, and CALL if from many places.

Thanks Dave, thats why i’v mention ( Even better )… To show my ( better practice ) evolution

Method that can be trigger by any other process… with the good parameter

If you subclass listbox you can use RaiseEvent not only from the CellClick event in the subclass, but also from any other method:

[code]Class MyListBox Inherits ListBox

// CellClick even definition
Event CellClick(row As Integer, column As Integer, x As Integer, y As Integer) As Boolean

// CellClick event handler
Function CellClick(row as Integer, column as Integer, x as Integer, y as Integer) As Boolean
Return RaiseEvent CellClick(row, column, x, y)
End Function

Sub Open()
Call RaiseEvent CellClick(0, 0, 0, 0)
End Sub

End Class[/code]