GridViewCommandColumn PerformClick

7 posts, 0 answers
  1. Roberto Wenzel
    Roberto Wenzel avatar
    41 posts
    Member since:
    Sep 2012

    Posted 19 Nov 2016 Link to this post

    Hello,

    I need some help with my application code.

    I'm trying to do a PerformClick on a CommandColumn in a single row in a single cell.

    How can I access the ButtonElement in that cell and do a PerformClick event programmatically?

    Thanks in advance

    Roberto

  2. Dimitar
    Admin
    Dimitar avatar
    2818 posts

    Posted 21 Nov 2016 Link to this post

    Hello Roberto,

    Since RadGridView is using UI Virtualization you cannot directly access the button. In your case you can just raise the CommandCellClick event which is the default action:
    private void RadButton1_Click(object sender, EventArgs e)
    {
        GridViewCellEventArgs args = new GridViewCellEventArgs(radGridView1.Rows[4], radGridView1.Columns[4], radGridView1.GridViewElement.ActiveEditor);
        radGridView1.MasterTemplate.EventDispatcher.RaiseEvent<GridViewCellEventArgs>(EventDispatcher.CommandCellClick, radGridView1, args);
    }

    I hope this will be useful. Let me know if you have additional questions.

    Regards,
    Dimitar
    Telerik by Progress
    Telerik UI for WinForms is ready for Visual Studio 2017 RC! Learn more.
  3. Roberto Wenzel
    Roberto Wenzel avatar
    41 posts
    Member since:
    Sep 2012

    Posted 21 Nov 2016 in reply to Dimitar Link to this post

    Hello Dimitar,

    thank you very much for your reply. That looks quite good. Unfortunately I always get an error with the GridViewElement.ActiveEditor which seems to be Nothing (in VB).

    This is my code (translated into VB)

    Private Sub AutoClick(ByVal rowindex As Integer, ByVal colindex As Integer)
        Dim args As GridViewCellEventArgs = New GridViewCellEventArgs(rgv_Prefixes.Rows(rowindex), rgv_Prefixes.Columns(colindex), rgv_Prefixes.GridViewElement.ActiveEditor)

    rgv_Prefixes.MasterTemplate.EventDispatcher.RaiseEvent(Of GridViewCellEventArgs)(EventDispatcher.CommandCellClick, rgv_Prefixes, args)
    End Sub

     

    When runnig the code GridViewElement.ActiveEditor is always Nothing. Any idea?

    Cheers Roberto

     

  4. Dimitar
    Admin
    Dimitar avatar
    2818 posts

    Posted 22 Nov 2016 Link to this post

    Hello Roberto,

    Actually, this is expected at this point because the grid is not focused when the event is raised (the grid has ActiveEditor only when a cell value is edited). However, this should not stop you to execute the event.  

    Please do not hesitate to contact us with any additional questions or concerns. 

    Regards,
    Dimitar
    Telerik by Progress
    Telerik UI for WinForms is ready for Visual Studio 2017 RC! Learn more.
  5. Roberto Wenzel
    Roberto Wenzel avatar
    41 posts
    Member since:
    Sep 2012

    Posted 22 Nov 2016 in reply to Dimitar Link to this post

    Hello Dimitar,

    thanks again.

    Unfortunatelly the code is not executed and throws an exception when GridViewElement.ActiveEditor is Nothing.

    I will find another solution for my problem.

    Thank you Roberto

  6. Dimitar
    Admin
    Dimitar avatar
    2818 posts

    Posted 22 Nov 2016 Link to this post

    Hello Roberto,

    I have attached a small sample that shows how this works.

    In addition please make sure that the correct row/column indexes are passed. 

    I hope this will be useful. 

    Regards,
    Dimitar
    Telerik by Progress
    Telerik UI for WinForms is ready for Visual Studio 2017 RC! Learn more.
  7. Roberto Wenzel
    Roberto Wenzel avatar
    41 posts
    Member since:
    Sep 2012

    Posted 24 Nov 2016 in reply to Dimitar Link to this post

    Hello Dimitar,

    thank you very much for the example. I will try that out.

    Bye Roberto

Back to Top