Children element label NullReferenceException

13 posts, 0 answers
  1. Alan
    Alan avatar
    7 posts
    Member since:
    Nov 2006

    Posted 14 Apr 2009 Link to this post

    An error occurs in the cellFormating event:

    in the first databinding of gridview the error does not happen , but if I try  a second databinding, for refresh the gridview,
    the following error occurs:

    System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
       at Telerik.WinControls.Primitives.TextPrimitive.MeasureOverride(SizeF availableSize)

    The code where the error occurs is the folowing:

     private void gvPremios_CellFormatting(object sender, CellFormattingEventArgs e)  
                             {  
     if (e.CellElement.ColumnInfo is GridViewDataColumn && !(e.CellElement.RowElement is GridTableHeaderRowElement))  
                                 {  
                                         GridViewDataColumn column = (GridViewDataColumn)e.CellElement.ColumnInfo;  
     
                                         if (column.DataField == "MyColumn")  
                                         {                         
                                             if (e.CellElement.Children.Count > 0)  
                                                 return;  
     
                                             RadLabelElement element = new RadLabelElement();  
                                             element.Text = "<html>This is a test..."                                           
                                            e.CellElement.Children.Add(element);  
                                         }  

    The strange thing is in the "element.text" property, that if I not put the the tag "<html>"... the error does not happen, but, i need formating the field with a html code...
    And the property "DisableHTMLRendering=false"  is not working as it should, leaving the whole column unconfigured.

  2. Alan
    Alan avatar
    7 posts
    Member since:
    Nov 2006

    Posted 14 Apr 2009 Link to this post

    Somebody help-me?
  3. UI for WinForms is Visual Studio 2017 Ready
  4. gerbrand
    gerbrand avatar
    78 posts
    Member since:
    Mar 2009

    Posted 15 Apr 2009 Link to this post

    Hi Alan,

    On which line is the error triggered?




  5. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 15 Apr 2009 Link to this post

    Hi Alan,

    You can find the answer in your support ticket regarding the same topic.

    Greetings,
    Nikolay
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  6. Alan
    Alan avatar
    7 posts
    Member since:
    Nov 2006

    Posted 15 Apr 2009 Link to this post

    Hi,

    there is no new response in the ticket system.
    the property "DisableHTMLRendering=false"  is not working as it should, leaving the whole column unconfigured.


    gerbrand
    The error occurs after leaving the CellFormating event, and only in the second databinding of the gridview.
    but if, i not put the "<html>" tag in the element.Text, the error does not happen.
    there is a way to reset the gridview, let him clean before the next databinding, or some other solution?


    thanks for attention.
  7. gerbrand
    gerbrand avatar
    78 posts
    Member since:
    Mar 2009

    Posted 15 Apr 2009 Link to this post

    Hi Alan,

    You can clean your gridview like this:

    1 radgridview.MasterGridViewTemplate.Columns.Clear(); //clears the columns 
    2 radgridview.MasterGridViewTemplate.Rows.Clear(); //clears the rows 
    3 radgridview.MasterGridViewTemplate.ChildGridViewTemplates.Clear(); //clears the childs 

    I'm binding my data in my code and not by datasource, so I'm not getting this error. I'm not sure how you are doing the databinding?
    (by datasource?)







  8. Alan
    Alan avatar
    7 posts
    Member since:
    Nov 2006

    Posted 15 Apr 2009 Link to this post

    Hi gerbrand,

    I clean the childs and the rows, but the error still happening.

    I'm binding using the follow code:

    Gridview.MasterGridViewTemplate.LoadFrom(IDatareader); 

    but have also tested it with datasource...

    you can show me as it did in your code?
    so I compare with my code.

    Thanks for your help.
  9. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 15 Apr 2009 Link to this post

    Hi Alan,

    You have opened two inquiries with the same question. Since support tickets get higher priority, we replied there first. The next day we noticed that you have the same question posted in the forums - this is why we replied to look into your support question.

    We would also prefer to continue addressing this question in just one thread - this will make sure that we have all information in one place, rather than jumping back and forth between different threads. This will make us respond faster and more accurately.

    Thank you for your understanding. We will reply in this thread shortly.

    Kind regards,

    Nikolay
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  10. gerbrand
    gerbrand avatar
    78 posts
    Member since:
    Mar 2009

    Posted 15 Apr 2009 Link to this post

    Hi Alan,

    Well I've got an List<Object> (where Object is a collecion of getters and setters) that I'm filling up first.
    (because I need data from more than one table )
    After that I'm looping my List<Object> and set my griddata like described in the helpfiles of the RadGridView

    Gridview.MasterGridViewTemplate.Rows.Add(new object[] { "Another new product", 456 }); 



    I can give you a more detailed example if you want...


  11. Alan
    Alan avatar
    7 posts
    Member since:
    Nov 2006

    Posted 15 Apr 2009 Link to this post

    Hello, gerbrand

    Yes, I would be grateful if you could please pass details of your code.

    if possible an example of how to perform the binding with a list of objects, i will try it this way.

    Thanks again.
  12. gerbrand
    gerbrand avatar
    78 posts
    Member since:
    Mar 2009

    Posted 15 Apr 2009 Link to this post

    Hi Alan,

    Here is an example of how I do it.

    1 //clear the gridview of everything 
    2 rgvNetwork.MasterGridViewTemplate.Columns.Clear(); 
    3 radGridView.MasterGridViewTemplate.Rows.Clear(); 
    4 radGridView.MasterGridViewTemplate.ChildGridViewTemplates.Clear(); 
    5  
    6  
    7 //add the columns for the master 
    8 radGridView.MasterGridViewTemplate.Columns.Add(new GridViewDataColumn { FieldName = "Id", HeaderText = "Name", HeaderTextAlignment = ContentAlignment.MiddleCenter }); 
    9 radGridView.MasterGridViewTemplate.Columns.Add(new GridViewDataColumn { FieldName = "Name", HeaderText = "Adserver Id", HeaderTextAlignment = ContentAlignment.MiddleCenter }); 
    10 radGridView.MasterGridViewTemplate.Columns.Add(new GridViewDataColumn { FieldName = "Active", HeaderText = "Active", HeaderTextAlignment = ContentAlignment.MiddleCenter }); 
    11  
    12 //add the columns for the childs 
    13 var template = new GridViewTemplate { AllowAddNewRow = false, AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill }; 
    14 template.Columns.Add(new GridViewTextBoxColumn { FieldName = "Id", IsVisible = false }); 
    15 template.Columns.Add(new GridViewTextBoxColumn { FieldName = "IdChild", HeaderText = "Zone Name", HeaderTextAlignment = ContentAlignment.MiddleCenter}); 
    16 template.Columns.Add(new GridViewTextBoxColumn { FieldName = "NameChild", HeaderText = "Zone Id", HeaderTextAlignment = ContentAlignment.MiddleCenter}); 
    17  
    18 //add the childtemplate to the master 
    19 radGridView.MasterGridViewTemplate.ChildGridViewTemplates.Add(template); 
    20  
    21 //make the relationship between master and child 
    22 var relation = new GridViewRelation(radGridView.MasterGridViewTemplate) 
    23             { 
    24                 ChildTemplate = template, 
    25                 RelationName = "SiteZonesNetwork" 
    26             }; 
    27  
    28 relation.ParentColumnNames.Add("Id"); //equals the fieldname 
    29 relation.ChildColumnNames.Add("Id"); //equals the fieldname 
    30  
    31 //add the relation 
    32 radGridView.Relations.Add(relation); 
    33  
    34  
    35 //load your List<Master> 
    36 var myListMaster = new List<Master>(); 
    37  
    38 var child1 = new List<Child>(); 
    39 child1.Add(new Child{ Id = 2, Name = "ChildTest2" }); 
    40 child1.Add(new Child{ Id = 3, Name = "ChildTest3" }); 
    41  
    42 var child2 = new List<Child>(); 
    43 child1.Add(new Child{ Id = 5, Name = "ChildTest5" }); 
    44 child1.Add(new Child{ Id = 6, Name = "ChildTest6" }); 
    45 child1.Add(new Child{ Id = 7, Name = "ChildTest7" }); 
    46  
    47 myListMaster.Add(new Master { Id = 1, Name = "Test", Childs = child1 }); 
    48 myListMaster.Add(new Master { Id = 4, Name = "Test2", Childs = child2 });                         
    49  
    50  
    51 //fill the radgridview 
    52 foreach(var myMaster in myListMaster){ 
    53  
    54   radGridView.MasterGridViewTemplate.Rows.Add(new object[] { myMaster.Id, myMaster.Name, myMaster.Active }); 
    55   template = radGridView.MasterGridViewTemplate.ChildGridViewTemplates[0]; 
    56    
    57   foreach(var child in myMaster.childs){ 
    58    
    59     template.Rows.Add(new object[] { myMaster.Id, child.Id, child.Name }); 
    60   } 
    61    
    62

    Where my 2 objects are written like this:
    1 public class Master{ 
    2   public int Id {get;set;} 
    3   public string Name {get;set;} 
    4   public List<Child> Childs{get;set;} 
    5
    6  
    7 public class Child{ 
    8   public int Id{get;set;} 
    9   public string Name {get;set;} 
    10


    It's possible that I have typo's in the example code. I wrote it quickly in notepad. But I think you will get the idea.


  13. Alan
    Alan avatar
    7 posts
    Member since:
    Nov 2006

    Posted 15 Apr 2009 Link to this post

    Thank you very much for helping me.
  14. Nikolay
    Admin
    Nikolay avatar
    1803 posts

    Posted 22 Apr 2009 Link to this post

    Hi Alan,

    You can find the answer to your question about the HTML rendering in your support ticket.

    gerbrand, thank you for your community efforts. I have updated your Telerik points.

    Kind regards,
    Nikolay
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top
UI for WinForms is Visual Studio 2017 Ready