Hi,
We are using Telerik RadGridView controls for my Silverlight application and we need to have export to excel functionality by implementing context menu. So, when user right clicks the grid, context menu should appear and on clicking on one menu item, it should export the grid data to excel. We are following MVVM models.
Below is my code snippets:
View:
<Telerik:RadGridView x:Name="Grid1" ...>
<Telerik:RadContextMenu.ContextMenu>
<Telerik:ContextMenu Name="Menu1">
<Telerik:MenuItem Header = "Export to Excel" Command="{Binding ExportCommand}" CommandParameter="{Binding ElementName=Grid1}">
</Telerik:MenuItem>
</Telerik:ContextMenu>
</Telerik:RadContextMenu.ContextMenu
</Telerik:RadGridView>
In ViewModel, I have created the ICommand variable "ExportCommand" as below
public ICommand ExportCommand
{
get
{
_exportCommand = new DelegateCommand<object>(
commandParameter => {
var grid = commandParameter as RadGridView;
.... put all the code to show dialog for exporting to excel which is working in other forms perfectly
..... but with CommandButton
grid.Export()
}
);
return _exportCommand;
}
}
I am not getting the grid to export. On executing below line, the grid variable becomes null. So no data to export to excel.
var grid = commandParameter as RadGridView;
Kindly help.
Thanks,
Meehir Jha