Jump to content

Programmatically selecting rows in a MCLB


Recommended Posts

In a multi column list box, you can select multiple items (if you set the list boxtox an array datatype) by clicking on items while holding down CTRL or by clicking on a first item and then holding down shift and selecting the last item in a range you wish to select.

I want to display a listbox of data and allow the user to select items in this way. BUT, I want to preselect the first item for them. So, all they would need to do is hold down shift and select the last item to choose a range. Unfortunately, I cannot get this to work. Here is what I have tried:

I have set the value of the control to an array containing only the first selected row’s element (even using value signaling).

I have set the edit position to the first selected row.

I have set the ActiveCell to the first selected row.

All of this is done before the user is allowed to select anything.

But, the issue remains, the user cannot select a range without first physically selecting the starting row, even if that row has already been programmatically selected by the application. Instead, when the VI first opens, the ‘first row’ is set to row 0. So, holding shift and selecting a row selects all rows from the top row to the clicked row.

Even weirder, if the user selects a new ‘first row’ when using the VI, whatever the user selects as this first row is remembered each time the VI is called, even if I have changed all the data being displayed and have ‘selected’ a different row programmatically.

Anyone know a way to get this to work as desired?

Thanks,

-John

Link to comment

Here are some VIs demoing the issue.

When the prompt VI appears, hold down shift and click on any row other than 0 or the selected row.

You will see the selection set to the rows from your clicked row to row 0. The programmatically selected row will be ignored.

Now, click on any other row (other than 0 or your programmatically selected row.)

Close the prompt VI.

Run the calling VI open the VI again.

This time hold shift and select any row other than row 0, the programmatically selected row or the last selected row before you closed the VI.

You will see the selection set to the row between your newly clicked row and the row you last clicked on before closing the VI the last time.

Confirmed in both 8.6.1 and 2009.

MCLB prompt.vi

Call MCLB prompt.vi

Link to comment

You can code this yourself by making the MCLB disabled or an indicator and using the Mouse Down event, coupled with the method which tells you which row was clicked based on the coords to do the entire selection programmatically. This has an additional advantage in that the user does not have to hold the shift key.

Link to comment

Also, to do this programmatically, you need to deal with many issues.

1. you cannot disable the control, because then the scroll bars will not work and the mouse scroll wheel will not work.

2. It does not matter if it is a control or indicator, because you will trap all the mouse down events and discard them anyways.

3. You must make sure the mouse down events you trap and process are 'in bounds' so you don't mess up clicks on the scroll bars.

4. You must process both shift and ctrl separately and mimic their normal behaviors.

5. Due to #4 you must save the last clicked row in the shift, ctrl and no modifier cases for use in the shift case. This is because the selection for the shift case is always between the clicked row and the last clicked row.

6. For the ctrl case, you must deal with both the add row and delete row if the row is already selected.

7. If your MCLB is set to 1 or more items, you must not allow all rows to be deselected in the ctrl case.

8. For the shift case, you must build an array of indexes for all value between the selected row and the last clicked row.

So, this is not trivial. And a real PITA to have to do just because you don't have access to the 'last clicked row' value of the native control.

Link to comment

I've hit this one before and it drives me crazy. All I can say is the behavior has been around for a long time. Way before 8.6. Sorry I can't offer anything constructive.

If it were easy to hook up .NET objects to event structures, I'd have abandoned the LV style lists ages ago, I can't stand the LV list controls implementation...

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.