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

Exporting From Grid in Windows Service

1 Answer 101 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jeremy Murtishaw
Top achievements
Rank 1
Jeremy Murtishaw asked on 21 Feb 2010, 09:01 AM
Hello,

I've got a windows service that I'd like to have an excel spreadsheet produced in. In the client, this is done via the Grid view Exporter. However, in the windows service, there are obviously no forms, so in order to do it this way, I would have to instantiate the RadGridView element, set its properties programmatically, set the datasource, and hope that it will be able to export a nicely formatted spreadsheet. When trying this, I was unable to get the grid's columns and rows to populate. Here is how I currently set it up:

grdResults.BackColor = System.Drawing.Color.White; 
                            //  
                            //  
                            //  
                            grdResults.MasterGridViewTemplate.AddNewRowPosition = Telerik.WinControls.UI.PinnedRowPosition.Bottom; 
                            grdResults.MasterGridViewTemplate.AllowAddNewRow = false
                            grdResults.MasterGridViewTemplate.AllowColumnChooser = false
                            grdResults.MasterGridViewTemplate.AllowDeleteRow = false
                            grdResults.MasterGridViewTemplate.AllowEditRow = false
                            grdResults.MasterGridViewTemplate.AllowRowResize = false
                            grdResults.MasterGridViewTemplate.AutoGenerateColumns = true
                            grdResults.MasterGridViewTemplate.AutoSizeColumnsMode = Telerik.WinControls.UI.GridViewAutoSizeColumnsMode.Fill; 
                            grdResults.MasterGridViewTemplate.EnableGrouping = false
                            grdResults.MasterGridViewTemplate.ShowFilteringRow = false
                            grdResults.MasterGridViewTemplate.ShowRowHeaderColumn = false
                            grdResults.MultiSelect = true
                            grdResults.Name = "grdResults"
                            grdResults.ReadOnly = true
                            grdResults.ShowGroupPanel = false
                            grdResults.Size = new System.Drawing.Size(684, 461); 
                            grdResults.TabIndex = 15; 
                            grdResults.TabStop = false
                            ((Telerik.WinControls.UI.GridTableElement)(grdResults.GetChildAt(0))).AlternatingRowColor = System.Drawing.Color.FromArgb(((int)(((byte)(222)))), ((int)(((byte)(255)))), ((int)(((byte)(222))))); 
                            ((Telerik.WinControls.UI.GridTableElement)(grdResults.GetChildAt(0))).RowHeight = 18; 
                            grdResults.Size = new Size(1000, 700); 
                            grdResults.DataSource = objRecordList; 

After the datasource is set, there are still no rows or columns, even though this should produce 67 rows and four columns. Is there an easier way to produce the desired spreadsheet from my list of objects? Alternatively, is there something I can do to get the grid to behave better so I can leverage the build-in exporter?

Thanks!
Jeremy

1 Answer, 1 is accepted

Sort by
0
Martin Vasilev
Telerik team
answered on 24 Feb 2010, 07:53 AM
Hi Jeremy Murtishaw,

Thank you for contacting us. Because you do not show RadGridView it does not build its inner visual elements including rows and columns. You can try to force the creation of elements by calling LoadElementTree method:

this.radGridView1.LoadElementTree();

If this does not help, I will need an example that demonstrates your scenario. This will help me investigate your case further and provide accurate assistance.

Sincerely yours,
Martin Vasilev
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.
Tags
GridView
Asked by
Jeremy Murtishaw
Top achievements
Rank 1
Answers by
Martin Vasilev
Telerik team
Share this question
or