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
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
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
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
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
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
Hello Dimitar,
thank you very much for the example. I will try that out.
Bye Roberto