views:

333

answers:

2

I am trying to take text from a list box control and put it into a particular cell in a data Grid. I am using the following code:

    private void DG_DragDrop(object sender, DragEventArgs e)
    {
        DataGridView.HitTestInfo theHit = DG.HitTest(e.X, e.Y);
        int theCol = theHit.ColumnX;
        int theRow = theHit.RowY;
        MessageBox.Show(theCol.ToString() + " " + theRow.ToString());

    }

By the column and row coordinates are always -1. I suspect the X and Y coming in need to be adjusted somehow, but I am not sure how or if this is the problem. Any ideas or suggestions would be appreciated...

A: 

I found the answer, here is the code in case anyone else has a similar problem:

   Point theLoc = DG.PointToClient(new Point(e.X, e.Y));

        DataGridView.HitTestInfo theHit = DG.HitTest(theLoc.X,theLoc.Y);
        int theCol = theHit.ColumnIndex;
        int theRow = theHit.RowIndex;
        MessageBox.Show(theCol.ToString() + " " + theRow.ToString());
Sparky
A: 

Hi, escuse me...

i have the same problem here... but im a little newbie in flex...

Can you show me an example? or send me one?

Thank you =)

Benjamin
The problem is the X and Y coordinates are relative to the screen, not the control itself. If your control is positioned at X=100,Y=200, height=100, Width=300. Then the screen coordinate of x=450, y=250 appears to be outside your control's position. However, if you adjust the screen coordinates by either a function like C# does, or simply but deducting your control's start points, the X=450 becomes X=350,y=250,becomes Y=50 within your control. I don't know Flex, so I can't really give you an example, sorry
Sparky
Thank you, you give me an idea...Sorry, i dont know that you are talking about C#But thank you for the explanation =)
Benjamin