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,
9 10361
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
(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... - public class TestLV : ListView
-
{
-
private const int WM_MOUSEMOVE = 0x200;
-
private const int WM_NCMOUSEMOVE = 0xA0;
-
-
protected override void WndProc(ref Message m)
-
{
-
base.WndProc(ref m);
-
-
switch (m.Msg)
-
{
-
case WM_MOUSEMOVE:
-
Console.WriteLine("Mouse moving (WM_MOUSEMOVE)...");
-
break;
-
case WM_NCMOUSEMOVE:
-
Console.WriteLine("Mouse moving (WM_NCMOUSEMOVE)...");
-
break;
-
}
-
}
-
}
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!
Its called "HotTracking" if that helps
Plater:
Can you elaborate a bit more? I am newbie.
Thanks
@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.
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.
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.
The only way to figure out what column header is being dropped is:
1. Find the area occupied by the header -
[DllImport("user32.dll")]
-
extern static IntPtr SendMessage(IntPtr hwnd, int message, int wParam, int lParam);
-
[DllImport("user32.dll")]
-
extern static bool GetWindowRect(IntPtr hwnd, out RECT rect);
-
-
const int LVM_GETHEADER = 4127;
-
-
struct RECT
-
{
-
public int left, top, right, bottom;
-
}
-
IntPtr hdrHandle = SendMessage(this.flContentLstView.Handle, LVM_GETHEADER, 0, 0);
-
RECT rc;
-
GetWindowRect(hdrHandle, out rc);
-
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. -
if (xPos >= rc.left && xPos <= rc.right && yPos >= rc.top && yPos <= rc.bottom)
-
{
-
int x = rc.left;
-
foreach (ColumnHeader column in this.listview.Columns)
-
{
-
x += column.Width;
-
if (xPos < x) return column;
-
}
-
}
-
}
-
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?
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
by: Sam Martin |
last post by:
hi all,
anyone know how i can detect this i c#?
tia
sam martin
|
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...
|
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....
|
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....
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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$) {
}
...
|
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...
|
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...
|
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
|
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...
|
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...
|
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...
|
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...
| |