"No Columns" when hosting gridView in RadHost

3 posts, 1 answers
  1. Nathan
    Nathan avatar
    2 posts
    Member since:
    Nov 2016

    Posted 22 Jun 2017 Link to this post

    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. Answer
    Dimitar
    Admin
    Dimitar avatar
    2834 posts

    Posted 23 Jun 2017 Link to this post

    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.
  3. Nathan
    Nathan avatar
    2 posts
    Member since:
    Nov 2016

    Posted 23 Jun 2017 in reply to Dimitar Link to this post

    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

     

Back to Top