LabVIEW - Listbox Clicked Index

· LabVIEW,listbox,index

I was writing some LabVIEW code with a multicolumn listbox and in some of my events, I have to figure out which index was clicked (e.g. "Shortcut Menu Activation?"). I first decided to try dividing Bounds.Area Height by the "Number of Rows". This number is compared to Position.Top and the Vertical Coordinates of the mouse click. In general, this will work if you're only showing, say, five rows. However, you lose a few pixels every row and then all of a sudden you're off by one row. Is there a better way? Fortunately yes.

In the code above, first I find the coordinates for the top of every cell. (I should note here that NumRows gives you the number of rows that are fully shown.) Then, in the event, I compare see which index the vertical coordinate corresponds to with the "Threshold 1D Array" VI. (I don't think I've ever used that before.) In case the user has scrolled down to more elements in the listbox, I also have to take that into account with TopLeft->Row.

I've played around with this code with varying sizes of listboxes and clicking all over and I think it works well. Let me know what you think.

Note: Everything here was tried with a multicolumn listbox, but I assume it would work with a normal listbox.