Home All Groups Group Topic Archive Search About
Author
11 Aug 2006 11:02 AM
pbaugh
I've got the following code for a datagridview :

        private void grdMain_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
        {
            Console.WriteLine(e.X.ToString() + ", " + e.Y.ToString());
        }

It never gets called, depite frantic clicking! Am I missing something?

Thanks

Author
11 Aug 2006 11:29 AM
Dubravko Sever
<pba***@recoilsoft.com> wrote in message
news:1155294166.136288.16590@p79g2000cwp.googlegroups.com...
> I've got the following code for a datagridview :
>
>        private void grdMain_MouseDown(object sender,
> System.Windows.Forms.MouseEventArgs e)
>        {
>            Console.WriteLine(e.X.ToString() + ", " + e.Y.ToString());
>        }
>
> It never gets called, depite frantic clicking! Am I missing something?
>
> Thanks
>

Send also where you have define mousevenethandler for that event... I don't
know what you trying to to, but usually I don't use MouseDown click instead
MouseUp event.

D.S.
Author
11 Aug 2006 12:07 PM
pbaugh
Hi,
The handler is :

this.grdMain.MouseDown += new
System.Windows.Forms.MouseEventHandler(this.grdMain_MouseDown);

The reason Im doing this is that I'm attempting to detect whether the
user is trying to sort a column on the grid so that I can intercept it
and put my own sort code in.

If there is a more appropriate event that I should be detecting for
this.. I'm open to ideas!

Many thanks
Author
11 Aug 2006 1:53 PM
Carl Daniel [VC++ MVP]
pba***@recoilsoft.com wrote:
> Hi,
> The handler is :
>
> this.grdMain.MouseDown += new
> System.Windows.Forms.MouseEventHandler(this.grdMain_MouseDown);
>
> The reason Im doing this is that I'm attempting to detect whether the
> user is trying to sort a column on the grid so that I can intercept it
> and put my own sort code in.
>
> If there is a more appropriate event that I should be detecting for
> this.. I'm open to ideas!

If you're using .NET 2.0 and DataGridView, you should see the
DataGridView.SortCompare event to manually sort elements in a DataGridView.

If you're using a DataGrid (.NET 1.x), then you have to do something else -
I can't help you with that though, as I never made friends with DataGrid.

-cd
Author
11 Aug 2006 2:08 PM
pbaugh
Carl,
Thanks for that, unfortunately I'd already taken a look at SortCompare
in MSDN and it would have been perfect, but I discovered that it
doesn't fire when the grid's datasource is set. Incidentally, it's a
datagridview in .NET 2.0 and it's bound to a datatable with one columns
sortmode set to 'programmatic'. I recoded the mousedown stuff from
scratch and miraculously it now works! (Must have had a typo in there
somewhere). Now I just need to correctly work out whether the coords
are over that particular column header.

Many thanks
Author
11 Aug 2006 2:14 PM
pbaugh
Bah! Just spotted the ColumnHeaderMouseClick event... that makes life a
bit easier lol!

AddThis Social Bookmark Button