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

Problem with hidden column

9 Answers 137 Views
GridView
This is a migrated thread and some comments may be shown as answers.
lee_bnsf
Top achievements
Rank 1
lee_bnsf asked on 25 Nov 2009, 03:43 PM
I need to show/hide columns based on a selection in a combobox.  The problem that I'm running into is that once a column is hidden and then I try to unhide it and set it's header to a new value, I get an "Object reference not set to an instance of an object" error.

Here's the code that's doing the showing and hiding.  If I uncomment the last line in the third case statement, I get the error when the value of sService goes from "MSSQL" to anything else.  As you can see, I'm setting the IsVisible property of the Misc5 column to true before trying to set the value of the header.

Any help is appreciated!
-Lee

 

Select Case sService  
                Case "MSOLAP" 
                    Me.grdServices.Columns("Misc5").IsVisible = True 
                    Me.grdServices.Columns("Misc1").IsVisible = False 
                    Me.grdServices.Columns("Misc2").IsVisible = False 
                    Me.grdServices.Columns("Misc3").Header = "Connections" 
                    Me.grdServices.Columns("Misc4").Header = "Sessions" 
                    Me.grdServices.Columns("Misc5").Header = "Memory (kb)" 
                Case "ReportServer" 
                    Me.grdServices.Columns("Misc5").IsVisible = True 
                    Me.grdServices.Columns("Misc1").IsVisible = False 
                    Me.grdServices.Columns("Misc2").IsVisible = False 
                    Me.grdServices.Columns("Misc3").Header = "Current Connections" 
                    Me.grdServices.Columns("Misc4").Header = "Ttl Rpts Executed" 
                    Me.grdServices.Columns("Misc5").Header = "Current Requests" 
                Case "MSSQL""MSSQLSERVER" 
                    Me.grdServices.Columns("Misc1").IsVisible = False 
                    Me.grdServices.Columns("Misc2").IsVisible = False 
                    Me.grdServices.Columns("Misc3").Header = "Connections" 
                    Me.grdServices.Columns("Misc4").Header = "Memory (kb)" 
                    Me.grdServices.Columns("Misc5").Header = "Misc5" 
                    'Me.grdServices.Columns("Misc5").IsVisible = False  
                Case Else 
                    Me.grdServices.Columns("Misc1").IsVisible = True 
                    Me.grdServices.Columns("Misc2").IsVisible = True 
                    Me.grdServices.Columns("Misc5").IsVisible = True 
                    Me.grdServices.Columns("Misc3").Header = "Misc3" 
                    Me.grdServices.Columns("Misc4").Header = "Misc4" 
                    Me.grdServices.Columns("Misc5").Header = "Misc5" 
            End Select 

 

 

 

9 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 01 Dec 2009, 06:57 AM
Hello Lee,

Can you verify using the debugger what exactly is null in your case? Stack trace of the exception will be helpful as well. Please post also more info about the grid version - latest build, Q3, other.

Sincerely yours,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
lee_bnsf
Top achievements
Rank 1
answered on 01 Dec 2009, 03:14 PM
Hi Vlad,

I'm using the Q3 release. At first I thought is was the reference to the Header property that was nothing, but after further examination, it appears that I can get the value of the Header property with no issues.  The error occurs when I try to set the value of the Header property.

So to recap, once a column is hidden using the IsVisible property, and then unhidden, setting the value of the Header property returns the "Object reference not set to an instance of an object" error. 

Thanks!
Lee 
0
Vlad
Telerik team
answered on 04 Dec 2009, 02:35 PM
Hi Lee,

I've just trued this using our latest binaries however didn't get any exceptions. You can check the attached project for reference.

Greetings,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Benjamin
Top achievements
Rank 1
answered on 16 Dec 2009, 05:26 PM
Vlad,

I am experiencing a similar problem.  Here is the stack trace for it.

at Telerik.Windows.Controls.GridView.GridViewHeaderCell.Column_PropertyChanged(Object sender, PropertyChangedEventArgs e)   
at Telerik.Windows.Controls.GridView.GridViewHeaderCell.Telerik.Windows.Data.IWeakEventListener<System.ComponentModel.PropertyChangedEventArgs>.ReceiveWeakEvent(Object sender, PropertyChangedEventArgs args)   
at Telerik.Windows.Data.WeakEvent.WeakListener`1.Handler(Object sender, TArgs args)   
at System.ComponentModel.PropertyChangedEventHandler.Invoke(Object sender, PropertyChangedEventArgs e)   
at Telerik.Windows.Controls.GridViewColumn.OnPropertyChanged(PropertyChangedEventArgs args)   
at Telerik.Windows.Controls.GridViewColumn.OnPropertyChanged(String propertyName)   
at Telerik.Windows.Controls.GridViewColumn.HeaderPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)   
at Telerik.Windows.PropertyMetadata.<>c__DisplayClass1.<Create>b__0(DependencyObject d, DependencyPropertyChangedEventArgs e)   
at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object newValue, Object oldValue)   
at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet, Boolean isSetByStyle, Boolean isSetByBuiltInStyle, PropertyInvalidationReason reason)   
at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value)   
at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)   
at Telerik.Windows.Controls.GridViewColumn.set_Header(Object value)   
at Telerik.Windows.Controls.GridViewBoundColumnBase.set_Header(Object value)   
at Dashboard.SC_Control.SetDetailUMforOverviewSubGrid(RadGridView table, Boolean isInLbs)

I am using the Q3 version 2009.3.1103.1030.  I have verified using the immediate window that there is in fact a value for both the header object and the String that I am setting it equal to.  It is pretty much the same senario that Lee has.  I am also within a VB Select Case.  There is a header set in xaml prior to run time.  I am now re-defining the header for the column at run time based upon logic  I am also using uniqueName to locate the column.

Ben
0
Vlad
Telerik team
answered on 17 Dec 2009, 07:19 AM
Hi Ben,

 Please upgrade to our latest official service pack (Q3 SP1) where this issue is fixed.


All the best,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Stefania Iszabela Nagy
Top achievements
Rank 1
answered on 17 Dec 2009, 02:06 PM
Hello,
i have just installed the latest version of telerik controls for silverlight (Q3 with SP1) and I have the same problem.

I load the date in my gridview dynamically at run time, and i need to set the id's column to IsVisible = false;
Here is the code:

<telerikGridView:RadGridView x:Name="DynamicGridView"
            AutoGenerateColumns="false" IsReadOnly="True" CanUserFreezeColumns="False">
</telerikGridView:RadGridView>

 DataTable table = new DataTable();
            int currentIndex = 0;
            DynamicGridView.Columns.Clear();
            foreach (string columnName in tableObject.ColumnNames)
            {
                table.Columns.Add(new DataColumn() { ColumnName = columnName, DataType = Type.GetType("System." + tableObject.ColumnTypeNames[currentIndex]) });
                GridViewDataColumn col = new GridViewDataColumn();
                if (_RemoveSorting) col.SortingState = SortingState.None;
                col.DataMemberBinding = new System.Windows.Data.Binding(columnName);
                col.Header = tableObject.ColumnCultureSpecificNames[currentIndex];
                col.IsReadOnly = true;
                if (MultipleSelect)
                {
                    col.IsSortable = false;
                    col.IsFilterable = false;
                    col.ShowDistinctFilters = false;
                    col.IsGroupable = false;
                    col.IsReorderable = false;
                }
                if (!_ShowPK && columnName == tableObject.PKColumnName)
                {
                    col.IsVisible = false;
                  
                }
                string showType = tableObject.ColumnShowTypes[currentIndex];
                if (!string.IsNullOrEmpty(showType))
                {
                    col.DataFormatString = showType;
                }
                DynamicGridView.Columns.Add(col);
                currentIndex++;
            }

            foreach (List<object> currentList in tableObject.RowValues)
            {
                DataRow row = new DataRow();
                int currentInsideIndex = 0;
                foreach (string columnName in tableObject.ColumnNames)
                {
                    row[columnName] = currentList[currentInsideIndex];
                    currentInsideIndex++;
                }
                table.Rows.Add(row);
            }

            _PKColumnName = tableObject.PKColumnName;

            DynamicGridView.ItemsSource = table;

Then, on the event OnRowLoaded, I need to get the  currentCell.DataColumn.DataMemberBinding.Path.Path, of Type GridViewCell for the column that was set to visible false. But that column does not appear within the list of GridViewCells for the loaded row. If I do not set that column to visible, false, it works just fine.

I really need to hide that column. Do you have any ideas what I should do?

Iszabela Nagy




0
Vlad
Telerik team
answered on 17 Dec 2009, 02:20 PM
Hi ,

 In RowLoaded you can get your object directly from e.Row.DataContext and get desired property value instead trying to access cells.


Sincerely yours,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Stefania Iszabela Nagy
Top achievements
Rank 1
answered on 18 Dec 2009, 07:17 AM
Hi,

I tried to using e.Row.DataContext, but i get nothing, and if I go in debug mode, and add e.Row.DataContext in the watchlist, it says:
  e.Row.DataContext Could not evaluate expression object

Do you have any other ideas? I tried with e.Row.DataItem. but it's the same as with DataContext.

Thank you,

Iszabela Nagy
0
Vlad
Telerik team
answered on 23 Dec 2009, 01:13 PM
Hello,

Since the grid is bound to dynamic types you cannot see this in the debugger however you can use reflection to get desired property:

var customerID = e.Row.DataContext.GetType().GetProperty("CustomerID").GetValue(e.Row.DataContext, null);

Regards,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
lee_bnsf
Top achievements
Rank 1
Answers by
Vlad
Telerik team
lee_bnsf
Top achievements
Rank 1
Benjamin
Top achievements
Rank 1
Stefania Iszabela Nagy
Top achievements
Rank 1
Share this question
or