Mouse Down does not change current row

9 posts, 0 answers
  1. dootndo2
    dootndo2 avatar
    10 posts
    Member since:
    Dec 2006

    Posted 18 Oct 2007 Link to this post

    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
  2. Jack
    Admin
    Jack avatar
    2333 posts

    Posted 19 Oct 2007 Link to this post

    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. dootndo2
    dootndo2 avatar
    10 posts
    Member since:
    Dec 2006

    Posted 19 Oct 2007 Link to this post

    That works great.

    Thanks for the awesome support.  It's appreciated.

    Dennis
  5. dootndo2
    dootndo2 avatar
    10 posts
    Member since:
    Dec 2006

    Posted 21 Dec 2007 Link to this post

    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

  6. Dwight
    Admin
    Dwight avatar
    475 posts

    Posted 27 Dec 2007 Link to this post

    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
  7. Abba
    Abba avatar
    22 posts
    Member since:
    Jan 2013

    Posted 26 Aug 2015 in reply to Dwight Link to this post

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

     

    Thanks

  8. Abba
    Abba avatar
    22 posts
    Member since:
    Jan 2013

    Posted 26 Aug 2015 in reply to Abba Link to this post

    I mean with latest control.  Because the getElementAtPoint does exist anymore.
  9. Stefan
    Admin
    Stefan avatar
    2890 posts

    Posted 27 Aug 2015 Link to this post

    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
  10. Abba
    Abba avatar
    22 posts
    Member since:
    Jan 2013

    Posted 27 Aug 2015 in reply to Stefan Link to this post

    PERFECT!

    Just what I needed and fast response.

     

    Thank you,

Back to Top
UI for WinForms is Visual Studio 2017 Ready