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

GridViewCommandColumn click event

5 Answers 1513 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Raghuramji Chandrasekaran
Top achievements
Rank 1
Raghuramji Chandrasekaran asked on 30 Jun 2010, 05:00 PM
I have a GridViewCommandColumn in my RAD Grid View. I want to handle the Command button click event. Please provide sample to how handle it.

5 Answers, 1 is accepted

Sort by
0
Jack
Telerik team
answered on 01 Jul 2010, 04:50 PM
Hi Raghuramji Chandrasekaran,

You should handle the CommandCellClick event. It fires every time when a command button is clicked. The sender argument contains the clicked cell. Here is a sample:

void radGridView1_CommandCellClick(object sender, EventArgs e)
{
    GridCommandCellElement cell = (GridCommandCellElement)sender;
    //...
}

Should you have any other question, don't hesitate to contact us.

Regards,
Jack
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Raghuramji Chandrasekaran
Top achievements
Rank 1
answered on 02 Jul 2010, 05:35 AM
Is it possible to disable a command button in the RADGridView at run time?
0
Jack
Telerik team
answered on 02 Jul 2010, 04:34 PM
Hi Raghuramji Chandrasekaran,

Yes, this is possible. You should handle CellFormatting event and set the Enabled property of the button. Please consider the sample below:

void radGridView1_CellFormatting(object sender, CellFormattingEventArgs e)
{
    GridViewDataColumn column = e.CellElement.ColumnInfo as GridViewDataColumn;
    if (column != null && column.UniqueName == "C")
    {
        GridCommandCellElement cell = (GridCommandCellElement)e.CellElement;
        if (cell.RowInfo.Cells["Value"].Value == null)
        {
            cell.CommandButton.Enabled = false;
        }
        else
        {
            cell.CommandButton.Enabled =(int)cell.RowInfo.Cells["Value"].Value > 10;
        }
    }
}

I hope this helps.

Best wishes,
Jack
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Arun
Top achievements
Rank 1
answered on 29 Oct 2012, 08:46 AM

Dear Folks,

I have a gridview with gridviewcommand colum and implemented CommandCellClick. But CommandCellClick event is not firing when user press enter / space on its focus.

Can anyone help me solve this issue.

Thanks
Arun

0
Jack
Telerik team
answered on 01 Nov 2012, 07:33 AM
Hi Arun,

This is the default behavior in RadGridView, the CommandCellClick event fires only when the button is pressed using the mouse. You can change this by using a custom grid behavior:
public class CustomGridBehavior : BaseGridBehavior
{
    public override bool ProcessKey(KeyEventArgs keys)
    {
        GridCommandCellElement cell = this.GridControl.CurrentCell as GridCommandCellElement;
        if (cell != null && (keys.KeyCode == Keys.Enter || keys.KeyCode == Keys.Space))
        {
            cell.CommandButton.CallDoClick(new MouseEventArgs(MouseButtons.Left, 1, 0, 0, 0));
            return false;
        }
        return base.ProcessKey(keys);
    }     
}

Use the following code to replace the behavior in RadGridView:
this.radGridView1.GridBehavior = new CustomGridBehavior();

I hope this helps.
 
Greetings,
Jack
the Telerik team
Q3’11 of RadControls for WinForms is available for download (see what's new). Get it today.
Tags
GridView
Asked by
Raghuramji Chandrasekaran
Top achievements
Rank 1
Answers by
Jack
Telerik team
Raghuramji Chandrasekaran
Top achievements
Rank 1
Arun
Top achievements
Rank 1
Share this question
or