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
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
Thanks for the awesome support. It's appreciated.
Dennis
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
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
I am having a similar need. But this is thread is old. How would I get the row in the mouse down event?
Thanks
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
PERFECT!
Just what I needed and fast response.
Thank you,