This project is read-only.

Hittest?

Jun 16, 2015 at 2:04 PM
I get that SourceGrid does not support a DropDrop event (booo!) but it does support a MouseUp event. If I can figure out which cell is being dropped to, I'm almost home. Any ideas?

Thanks in advance.
Jun 16, 2015 at 2:29 PM
I spoke too soon. MouseUp doesn't help if you're dragging and dropping.

In case you were curious, here is my Hittest solution:
                int _MouseX = e.Location.X;
                int _MouseY = e.Location.Y;

                int _X = this.Location.X;
                int _Y = this.Location.Y;

                int c = -1;
                int r = -1;

                while (_X < _MouseX)

                    _X += this.Columns[++c].Width;

                while (_Y < _MouseY)

                    _Y += this.Rows[++r].Height;

                //Selected cell is this[r, c].
                Console.WriteLine(" row = " + r + " col = " + c);
Jun 16, 2015 at 3:56 PM
And the hits keep coming.

So, SourceGrid does have a DrapDrop event, you just have to remember to enable AllowDrop (ooops).
            void MyGrid_DragDrop(object sender, DragEventArgs e)
            {

                Point p = this.PointToClient(new Point(e.X, e.Y));
                
                int _X = this.Location.X;
                int _Y = this.Location.Y;

                int c = -1;
                int r = -1;

                while (_X < p.X)

                    _X += this.Columns[++c].Width;

                while (_Y < p.Y)

                    _Y += this.Rows[++r].Height;

                //Selected cell is this[r, c].
                Console.WriteLine(" row = " + r + " col = " + c);

            }
Marked as answer by brightak on 6/16/2015 at 7:56 AM