This is a migrated thread and some comments may be shown as answers.

Mouse Down does not change current row

8 Answers 470 Views
GridView
This is a migrated thread and some comments may be shown as answers.
dootndo2
Top achievements
Rank 1
dootndo2 asked on 19 Oct 2007, 12:12 AM
I have been working on an application that allows the user to click on a row in the RadDataGridView and drag and drop the row as an object to a separate control.  The drag and drop is itself is working, but I have come across an issue.

When the MouseDown event fires, the RadGridView.MasterGridViewInfo.CurrentRow is not updated with the correct selected row.  When the user drops the object on the other control, I am receiveing the wrong object.

If I click on a row, ensure that the selected item was updated, then drag and drop it works.

Is this a bug, or is there a work around?  The MouseDown event fires before the CurrentRowChanged event fires. 

Is there a way to set the CurrentRow based upon the row that was clicked?

Thanks.

Dennis

8 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 19 Oct 2007, 08:21 AM
Hello dootndo2,

We reproduced this issue locally. We will reconsider the sequence of events fired in our upcoming version.

As a workaround you can get the current hovered element by using the  following code:

this.radGridView1.MouseDown += new MouseEventHandler(radGridView1_MouseDown); 
 
void radGridView1_MouseDown(object sender, MouseEventArgs e) 
    RadElement element = this.radGridView1.GetElementAtPoint(e.Location); 
    if (element != null
    { 
        GridRowElement row = element.Parent as GridRowElement; 
        if (row != null
        { 
            // enter drag drop logic here 
        } 
    } 

We will be glad to help you if you have any additional questions.

Sincerely yours,
Jack
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
dootndo2
Top achievements
Rank 1
answered on 19 Oct 2007, 01:55 PM
That works great.

Thanks for the awesome support.  It's appreciated.

Dennis
0
dootndo2
Top achievements
Rank 1
answered on 21 Dec 2007, 07:19 PM
Thanks for your previous help. 

I am making an update to this per our customers request and I have hit a snag.  Since the CurrentRow property is not being updated, I cannot get the index of the current row based upon this solution.  I have attempted to iterate over the rows using the row.RowInfo.DataBound item to find the object that the items is bound to to get the row.  I can do a for loop that will convert a GridViewRowInfo to a GridRowElement, but I cannot do a CType() to do the same process in a for i = 0 type loop.

Unfortunately, I keep getting this compiler error:

Value of type 'Telerik.WinControls.UI.GridViewInfo' cannot be converted to 'Telerik.WinControls.UI.GridViewRowInfo'.

This occurs in the following code:

Private

Function GetCurrentSelectedRow(ByVal piece As PieceEntity) As Integer
 
Dim retVal As Integer = -1
 
For Each row As GridRowElement In grdBin.Rows
   
If piece.PieceId = CType(row.RowInfo.DataBoundItem, PieceEntity).PieceId Then
     
' set current row
     
grdBin.CurrentRow = row.GridViewInfo ' ERROR OCCURS HERE!
     
Return grdBin.Rows.IndexOf(grdBin.CurrentRow)
   
End If
  
Next
 
Return retVal
End Function


Any help with this would be helpful.  I am trying to do the following:

1.  User drags and drops the row to a separate control (working fine)
2.  System will identify the index of the row dragged
3.  System will remove the row and rebind the control
4.  System will scroll the grid to the index that contained the original dragged row.  (So if it is 20 out of 100, after drag and drop row 21 becomes 20 and grid is scrolled to 20)

Thanks.
Dennis

0
Dwight
Telerik team
answered on 27 Dec 2007, 08:50 AM
Hello Dennis,

Thank you for contacting us.

Please, change the following line of code:
 
grdBin.CurrentRow = row.GridViewInfo

with this one:

grdBin.CurrentRow = row.RowInfo 

Please, let us know if that helps. If you have any additional questions, please let us know.

Best regards,
Evtim
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Abba
Top achievements
Rank 1
answered on 27 Aug 2015, 03:14 AM

I am having a similar need.  But this is thread is old.  How would I get the row in the mouse down event?

 

Thanks

0
Abba
Top achievements
Rank 1
answered on 27 Aug 2015, 03:16 AM
I mean with latest control.  Because the getElementAtPoint does exist anymore.
0
Stefan
Telerik team
answered on 27 Aug 2015, 11:29 AM
Hello Abba,

Here is how to access the data row in the MouseDown event:
void radGridView1_MouseDown(object sender, MouseEventArgs e)
{
    GridCellElement clickedCell = radGridView1.ElementTree.GetElementAtPoint(e.Location) as GridCellElement;
    if (clickedCell != null)
    {
        GridViewRowInfo row = clickedCell.RowInfo;
    }
}

I hope this helps.

Regards,
Stefan
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Abba
Top achievements
Rank 1
answered on 28 Aug 2015, 01:37 AM

PERFECT!

Just what I needed and fast response.

 

Thank you,

Tags
GridView
Asked by
dootndo2
Top achievements
Rank 1
Answers by
Jack
Telerik team
dootndo2
Top achievements
Rank 1
Dwight
Telerik team
Abba
Top achievements
Rank 1
Stefan
Telerik team
Share this question
or