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

"No Columns" when hosting gridView in RadHost

2 Answers 47 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Nathan
Top achievements
Rank 1
Nathan asked on 23 Jun 2017, 03:09 AM

Hi, I've tried to create a radGridView control programmatically so I can host it inside of a radHostControl, I do believe the problem has nothing to do with hosting as it occurs before I host it. : When I create teh control using the following code, I give it a Datasource which has data, however the control reports that it has no columns in its properties. And continuing, the control actually shows the data and all the columns when the app is live; the problem being I can't access these columns as they apparently do not exist:

            RadGridView gridView = new RadGridView();
            Telerik.WinControls.UI.TableViewDefinition tableViewDefinition14 = new Telerik.WinControls.UI.TableViewDefinition();

            gridView.BeginInit();
            gridView.MasterTemplate.BeginInit();

            gridView.Size = new Size(100, 300);
            gridView.AutoGenerateColumns = true;
            gridView.DataSource = blacklistProps;
            getBlacklist();

            gridView.MasterTemplate.AllowAddNewRow = false;
            gridView.MasterTemplate.AllowColumnChooser = false;
            gridView.MasterTemplate.AllowColumnHeaderContextMenu = false;
            gridView.MasterTemplate.ShowColumnHeaders = false;
            gridView.MasterTemplate.ShowFilteringRow = false;
            gridView.MasterTemplate.ShowRowHeaderColumn = false;
            gridView.MasterTemplate.ViewDefinition = tableViewDefinition14;
            gridView.Name = "blacklistGridView";

            gridView.RootElement.MinSize = new System.Drawing.Size(0, 0);
            gridView.ShowGroupPanel = false;
            //gridView.Size = new System.Drawing.Size(316, 381);
            gridView.TabIndex = 0;

            gridView.ContextMenuOpening += new Telerik.WinControls.UI.ContextMenuOpeningEventHandler(this.gridViewMappings_ContextMenuOpening);

            gridView.MasterTemplate.EndInit();
            gridView.EndInit();

2 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 23 Jun 2017, 11:01 AM
Hi Nathan,

In general, the grid is created when it is added to the form which sets it BindingContext. You can do this manually by setting the BindingContext and calling the LoadElementTree method:
//other code
gridView.MasterTemplate.EndInit();
gridView.EndInit();
 
gridView.BindingContext = new BindingContext();
gridView.LoadElementTree();
 
Console.WriteLine(gridView.Columns.Count);

I hope this will be useful. Let me know if you have additional questions.

Regards,
Dimitar
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Nathan
Top achievements
Rank 1
answered on 23 Jun 2017, 12:10 PM

Oh awesome! Thanks heaps for the reply! That did the trick, I had a feeling it had to do with the BindingContext when i was looking through the properties but wasn't sure! And I wouldnt have guessed to Load the Element tree after that. thankyou heapss

 

Tags
GridView
Asked by
Nathan
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Nathan
Top achievements
Rank 1
Share this question
or