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

GridViewCommandColumn PerformClick

6 Answers 250 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Roberto Wenzel
Top achievements
Rank 2
Roberto Wenzel asked on 19 Nov 2016, 12:57 PM

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

6 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 21 Nov 2016, 08:43 AM
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.
0
Roberto Wenzel
Top achievements
Rank 2
answered on 21 Nov 2016, 12:58 PM

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

 

0
Dimitar
Telerik team
answered on 22 Nov 2016, 09:25 AM
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.
0
Roberto Wenzel
Top achievements
Rank 2
answered on 22 Nov 2016, 10:15 AM

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

0
Dimitar
Telerik team
answered on 22 Nov 2016, 10:38 AM
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.
0
Roberto Wenzel
Top achievements
Rank 2
answered on 24 Nov 2016, 10:55 AM

Hello Dimitar,

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

Bye Roberto

Tags
GridView
Asked by
Roberto Wenzel
Top achievements
Rank 2
Answers by
Dimitar
Telerik team
Roberto Wenzel
Top achievements
Rank 2
Share this question
or