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

Implementing a custom command column

3 Answers 34 Views
Grid for XAML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
anthony
Top achievements
Rank 1
anthony asked on 01 Oct 2014, 03:01 AM
Hello,

I want to add a custom command column in my grid. It looks great so far but I am having trouble applying a row-specific parameter to the button. Can anyone assist me on this? 

My C# ItemSource looks like: 

public class AttendeeLookupViewModel
{
       public string Id { get; set; }
       public string FirstName { get; set; }
       public string LastName { get; set; }
}

My grid column XAML looks like: 

<grid:DataGridTemplateColumn CanUserEdit="False">
    <grid:DataGridTemplateColumn.CellContentTemplate>
        <DataTemplate>
            <Button Content="VIEW">
                <Button.Command>
                    <models:CustomGridCommand />
                </Button.Command>
            </Button>
        </DataTemplate>
    </grid:DataGridTemplateColumn.CellContentTemplate>
</grid:DataGridTemplateColumn>

My CustomGridCommand looks like:

public class CustomGridCommand : DataGridCommand
    {
        public CustomGridCommand()
        {
            this.Id = CommandId.CellTap;
        }

        public override bool CanExecute(object parameter)
        {
            DataGridCellInfo context = parameter as DataGridCellInfo;
            // put your custom logic here
            return true;
        }

        public override void Execute(object parameter)
        {
            DataGridCellInfo context = parameter as DataGridCellInfo;
            // put your custom logic here               
        }
    }

Any help is much appreciated!








3 Answers, 1 is accepted

Sort by
0
Ivaylo Gergov
Telerik team
answered on 03 Oct 2014, 01:39 PM
Hi,

Thank you for contacting us.

The RadDataGrid's commands are designed to allow different aspects of the RadDataGrid control’s behavior to be handled and/or completely overridden. These commands should be assigned in the RadDataGrid.Commands collection. For example, the CustomGridCommand that you have implemented will trigger after a CellTap has been made. They should not be assigned to custom UI elements.

Regards,
Ivaylo Gergov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
anthony
Top achievements
Rank 1
answered on 03 Oct 2014, 02:35 PM
Thanks so much for your reply, That makes sense and I now have the cell tap working, but the command is applied to every single cell in the grid. Is there any way to get only one column to respond to the custom command or is that a waste of time?
0
anthony
Top achievements
Rank 1
answered on 03 Oct 2014, 02:45 PM
Ok, so I sorted this by adding a Name value to the column itself and responding accordingly in my Execute function. 
Tags
Grid for XAML
Asked by
anthony
Top achievements
Rank 1
Answers by
Ivaylo Gergov
Telerik team
anthony
Top achievements
Rank 1
Share this question
or