Jump to content
John Lokanis

MCLB movable column separators and header click events.

Recommended Posts

I am stumped.  I created a MCLB that allows you to sort the data based on the column the user clicks on.  This is pretty simple.  Just trap the mouse down event and check if it is in the header row.  If so, find the column clicked and sort the data, then discard the event.  But then I wanted to add the ability to resize the columns however this did not work because the event would get discarded after doing the sort.  So I stopped discarding the events. But now I end up sorting the data every time I try to resize a column.  So, I need some way to detect if I am hovering over a column separator and have the resize cursor displayed and then use this fact to suppress the sort on mouse down events.

Any idea how to solve this?  Is it even possible?

 

thanks for any insights...

 

-John

Share this post


Link to post
Share on other sites

Handle the resizing in "Mouse Move" rather than mouse down and use the Point to Row Column property node to get whether you are in the header or not.

Share this post


Link to post
Share on other sites

Just to be clear, I am using the "Mouse Down?" event to perform the sort.  I do not have custom code to implement the resize.  That is provided by the MCLB control.

So, if I was to use the mouse move, how would I accomplish that?  The act of clicking anywhere on the control triggers the "Mouse Down?" event and the sort runs if the mouse is in the header.  I need to suppress this if I am doing a resize.  If I use "Mouse Move" that will trigger every time the mouse changes position over the control regardless of clicking.  How could I isolate that to suppress the sort while still allowing the click of the header to trigger the sort?

Share this post


Link to post
Share on other sites

I had this exact issue when I added column sorting to the Project Find dialog in LabVIEW 2013. It's cheesy, but the way I handled it was to store off the column widths of the columns on both sides of the mouse down whenever the Mouse Down event occurred:

 

post-4441-0-92338200-1415659430_thumb.pn

 

And then on Mouse Up, if I found that the column widths were different, I conclude that it's a column resize, and I don't do the sort:

 

post-4441-0-92067500-1415659431_thumb.pn

Share this post


Link to post
Share on other sites

Well if that is the best solution you could find, I doubt I will be able to do better.  I actually thought about this but really hoped there was a more elegant way to do this.  Thanks for confirming this solution.  I'll give it a whirl.

Share this post


Link to post
Share on other sites

No problem...it also gave me a chance to plug the fact that the column headers in the Project Find dialog are clickable for sorting in LabVIEW 2013 and later! ;)

Share this post


Link to post
Share on other sites

What about reading the mouse pointer?  If it is a ][ or what ever symbol then don't discard, and don't sort.

Share this post


Link to post
Share on other sites

sort or not.vi
 
Measuring column widths seems a bit overkill if you are not  auto fitting.

 

A point of reference. A single click to sort is not usually a desired operation especially for sorts that can take some time because it's just too easy to accidentally set it off. A double click to toggle is IMO more desirable.

Edited by ShaunR
  • Like 2

Share this post


Link to post
Share on other sites

Shaun I have to disagree, the standard Window's interaction is single click to sort, it's what's intuitive to most people so if the expectation isn't met I think it becomes a minor user gripe.

Share this post


Link to post
Share on other sites

The mouse move to 'disarm' the sort between a mouse down and mouse up did the trick.

 

Yeah, that is a simpler way to do it, I didn't think of that. The only thing to consider is that if the user is a little sloppy with his mouse (i.e. moves it a pixel or two between mouse down and mouse up), the sort won't trigger. Probably not a big deal, but something to keep in mind.

Share this post


Link to post
Share on other sites

Agreed, but when I tried it in practice, it seemed acceptable.

 

Now if I could just get mouse leave events to consistently fire before mouse enter events for adjacent controls, I would be a happy camper...

Share this post


Link to post
Share on other sites

Now if I could just get mouse leave events to consistently fire before mouse enter events for adjacent controls, I would be a happy camper...

 

Assuming both of these controls have the same owner, if you're seeing Mouse Enter before Mouse Leave, that sounds like a bug. Can you post a VI that demonstrates the issue?

Share this post


Link to post
Share on other sites

Well, they are in separate panes but on the same front panel.  And one is an Xctrl.  It seems to only happen when leaving the Xctrl and entering the MCLB in the adjacent pane.

I will have to build an example when I have some time.  The app where this is happening is way to big to post.

 

(Now I've thread-jacked my own thread!)

Edited by John Lokanis

Share this post


Link to post
Share on other sites

I will have to build an example when I have some time.  The app where this is happening is way to big to post.

 

Ok, when you get around to it, you can either PM me the example, or post it to forums.ni.com for an AE to take care of.

Share this post


Link to post
Share on other sites

Join the conversation

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

Guest
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.