473,387 Members | 3,781 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

What listview event fired when mouse over column header

17
I notice that when the mouse is over a column header of a listview control, that column header is focused (or highlighted). In this case, what event is fired ?

The reason I ask is I have listview control with 14 columns,
I also have labels that I want to drag-n-drop the labels over the listview column headers. When that occurs, I will change the column header text to the label text.

I have all the codes done for the drag-n-drop, but when I drop the label on the listview column header, I struggle to find out which column is being "dropped", and what listview event is kicked off.

Thanks,
May 20 '10 #1
9 10361
GaryTexmo
1,501 Expert 1GB
I know this doesn't help, but I have no idea!!

I tried creating a new class inheriting from ListView and overriding WndProc for a WM_MOUSEMOVE message but it doesn't go when you're over the header. Very strange! It's like the header is a completely separate control somehow within the ListView control.

Now that you've brought this up, I'm quite interested to know (things that make no sense bug me, haha). I tried googling around but didn't get much on it... perhaps you should hit google too. Maybe someone else will have some ideas also.

*Edit: A thought occurred to me... I think there's some code on CodeProject that will let you see when a mouse event happens globally (not just on a form). It seems terribly inefficient, but you might be able to do something with that to see if the cursor is within the bounds of the ListView's ClientRectangle (or whatever property it is) and the control is active. That seems rather hackish, but honestly I don't have any better ideas.

I feel like there's gotta be a better way :D
May 20 '10 #2
GaryTexmo
1,501 Expert 1GB
(See edit below)

Muahaha, I think I got it! :D [Ed: No, I didn't. BAH!]

You need to trap on the WM_NCMOUSEMOVE message. I guess the NC means non-client, and it goes when the mouse is on the non-client area of a form. Here's the MSDN page...

http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx

Here are all the windows messages...
http://www.autohotkey.com/docs/misc/SendMessageList.htm

It looks like this doesn't happen on every mouse move. It might be when you enter this section, I'm honestly not sure, but it's a start and I'll let you take it from here.

Here's some sample code to get you started...

Expand|Select|Wrap|Line Numbers
  1.     public class TestLV : ListView
  2.     {
  3.         private const int WM_MOUSEMOVE = 0x200;
  4.         private const int WM_NCMOUSEMOVE = 0xA0;
  5.  
  6.         protected override void WndProc(ref Message m)
  7.         {
  8.             base.WndProc(ref m);
  9.  
  10.             switch (m.Msg)
  11.             {
  12.                 case WM_MOUSEMOVE:
  13.                     Console.WriteLine("Mouse moving (WM_MOUSEMOVE)...");
  14.                     break;
  15.                 case WM_NCMOUSEMOVE:
  16.                     Console.WriteLine("Mouse moving (WM_NCMOUSEMOVE)...");
  17.                     break;
  18.             }
  19.         }
  20.     }
EDIT: I thought I had but I did not :( I only thought I was getting that message but I was just hitting it when mousing over the like, pixel of empty space between the control and the column header *sigh*. It looks like the only message that even comes while mousing over the column header is 4E, which is WM_NOTIFY. I'm not sure why... stumped again. Sorry!
May 20 '10 #3
Plater
7,872 Expert 4TB
Its called "HotTracking" if that helps
May 20 '10 #4
nghivo
17
Plater:

Can you elaborate a bit more? I am newbie.

Thanks
May 20 '10 #5
GaryTexmo
1,501 Expert 1GB
@Plater
I think HotTracking is something else... here's the doc

//
// Summary:
// Gets or sets a value indicating whether the text of an item or subitem has
// the appearance of a hyperlink when the mouse pointer passes over it.
//
// Returns:
// true if the item text has the appearance of a hyperlink when the mouse passes
// over it; otherwise, false. The default is false.
[DefaultValue(false)]
public bool HotTracking { get; set; }
Unless you mean this can be used to see when the mouse moves over a column header... if so, how?!

(This has me rightly confused. I showed a few colleagues here at work just 'cause it was so messed up and they were as confounded as I was :P)

nghivo, you might even want to consider going to microsoft's support site and bringing this up.
May 20 '10 #6
Plater
7,872 Expert 4TB
I'm not sure if it helps or not.
But the concept of having a visual reaction on mouseover in things like TabControls, TreeViews, etc is called HotTracking (thus the property). And if you turn it off, no visual changes will occur.
May 20 '10 #7
nghivo
17
Folks:

Thanks for your help,
I will contact Microsoft for help and research some more.
If I find the solution, I will post back here including some code.

In the meantime, if you have any new idea, please do throw in.
May 21 '10 #8
nghivo
17
The only way to figure out what column header is being dropped is:

1. Find the area occupied by the header
Expand|Select|Wrap|Line Numbers
  1.         [DllImport("user32.dll")]
  2.         extern static IntPtr SendMessage(IntPtr hwnd, int message, int wParam, int lParam);
  3.         [DllImport("user32.dll")]
  4.         extern static bool GetWindowRect(IntPtr hwnd, out RECT rect);
  5.  
  6.         const int LVM_GETHEADER = 4127;
  7.  
  8.         struct RECT
  9.         {
  10.             public int left, top, right, bottom;
  11.         }        
  12.             IntPtr hdrHandle = SendMessage(this.flContentLstView.Handle, LVM_GETHEADER, 0, 0);
  13.             RECT rc;
  14.             GetWindowRect(hdrHandle, out rc);
  15.  
2. Know the mouse position and the area occupied by the header, find the column that the mouse is "over". xPos is the mouse x position, yPos is the mouse y postion.

Expand|Select|Wrap|Line Numbers
  1.             if (xPos >= rc.left && xPos <= rc.right && yPos >= rc.top && yPos <= rc.bottom)
  2.             {
  3.                 int x = rc.left;
  4.                 foreach (ColumnHeader column in this.listview.Columns)
  5.                 {
  6.                     x += column.Width;
  7.                     if (xPos < x) return column;                    
  8.                 }
  9.             }
  10.        }
  11.  
May 28 '10 #9
GaryTexmo
1,501 Expert 1GB
How did you get the mouse position over the header? The mouse move events I tied into would only get the mouse movement over the control body itself, not the headers. I figured the solution would be something like this but I couldn't figure out how to get the mouse position in that area.

A couple of other things...

1. The code tags use square brackets, can you please replace your angle brackets with square brackets to fix your post?

2. When I was trying to help you out with this I found very little information on google. I think this would make a great article for the insights section. Would you be willing to write up a quick little article on this with some working code that people could use to figure this out?
May 28 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: rmorvay | last post by:
I have successfully integrated sorting in the listview control with the following code: Private Sub ListView_ColumnClick(ByVal sender As Object, ByVal e As...
1
by: Lex | last post by:
I want to write an app in C# that keeps track of when the foreground window in the OS changes. Is there an event that I can "susbscribe" to for this? Or am I stuck polling using the...
1
by: Sam Martin | last post by:
hi all, anyone know how i can detect this i c#? tia sam martin
5
by: objectref | last post by:
Hi to all, i populate a ListView with data from a datareader and i just want to know the column name of the cell that the user clicks on. E.x., if the user clicks on the 2nd column, 3rd row in...
2
by: hypomite | last post by:
I have an handler for the SelectedIndexChanged event of a dropdown box. I have also set the AutoPostBack option to True. When you select any item besides the first one, the event sucessfully fires....
1
by: active | last post by:
I've been working on a problem for a few days now. I do not get a Double-Click event fired for a ListView when I double click. I now find that if I double click with the right button it works OK....
3
by: ±è¿ë°Ç | last post by:
i used a list view component to a form and i would like to do some thing when i click right mouse on the list view's column header but the mouse down event was not occured while i click list...
1
by: majestik | last post by:
Question, can I see an event in Javascript that tells me a video starts playing using the <embed src="file.wmv>. I stream the video, but there is a wait time and wanted to pop up a message telling...
2
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, I'm using the VS 2005 Express Edition for C#. In the GUI designer, when I try to set the text alignment to anything except Left for the first column of a ListView, it jumps back to the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.