Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
860
NullReferenceException when hiding a column
posted

Hello,

I've a WebDataGrid inside a WebDialogWindow as follows (no matter with or without the behaviours):

<ig:WebDataGrid ID="DlgFirezonesWDG" runat="server">
    <Behaviors>
        <ig:ColumnMoving></ig:ColumnMoving>
        <ig:ColumnResizing></ig:ColumnResizing>
        <ig:Filtering></ig:Filtering>
        <ig:Sorting></ig:Sorting>
        <ig:SummaryRow></ig:SummaryRow>
    </Behaviors>
</ig:WebDataGrid>

code behind:

List<area>f=area.GetList();
  //some fields: int id, string name, string number, subarea, ...
  //where subarea is of type area
AreasWDG.DataSource=f;
AreasWDG.DataKeyFields="id";
AreasWDG.DataBind();
AreasWDG.Columns[0].Hidden=true;

 

All other grid properties have default values.

Everything works fine as long as I do not try to hide a column which is what I really want to, since e. g. the subarea field is an entity object and does not need to show up.

If I try to hide a column, no matter using the index (0, 1 or whatever) or the key ("id", "subarea", ...) I get a NullReferenceException. This is because AreasWDG.Columns actually does not contain any columns. Nevertheless AreasWDG.Rows does (count=6) and AreasWDG.HasColumns is true.

Am I doing something wrong or why does this happen?

regards

Parents
  • 33839
    Verified Answer
    posted

    Hi bernhardus,

    You are actually doing something wrong.  HasColumns returns true if the internal columns collection has been defined, which happens when .Columns is accessed.  The problem however is that you are autogenerating your columns.  The columns collection contains only columns you have defined.  Autogenerated ones are available only internally.  This is how the grid has always worked.  If you want to work with the columns on the server, you should turn of AutoGenerateColumns and then create the columns from your data source.  Another solution I've seen on the forums is to access the internal column off of the Column property of  GridRecordItem (the cell) of a row.

    regards,
    David Young 

Reply Children
No Data