Error: A value of type 'GridViewDataColumn' cannot be added to a collection or dictionary of type 'GridViewColumnCollection'.

8 posts, 0 answers
  1. George
    George avatar
    2 posts
    Member since:
    Aug 2014

    Posted 03 Nov 2014 Link to this post

    Hi,

    Can someone tell me why I keep getting the following error when I try to set a CellStyle on a GridViewDataColumn in a RadGridView control?

    Error: A value of type 'GridViewDataColumn' cannot be added to a collection or dictionary of type 'GridViewColumnCollection'.

    Here is the xaml:

        <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" Header="Name">
         <telerik:GridViewDataColumn.CellStyle>
               <Style BasedOn="{StaticResource ReadOnlyStyle}" TargetType="{x:Type telerik:GridViewCell}" />
         </telerik:GridViewDataColumn.CellStyle>
        </telerik:GridViewDataColumn>

    All I am trying to do is create a style - ReadOnlyStyle - that would set the foreground color of a grid column to a gray color when the style is set. Here is the style:

        <!--  GridView: Read Only Style  -->
        <Style x:Key="ReadOnlyStyle" TargetType="telerik:GridViewCell">
            <Setter Property="Foreground" Value="{DynamicResource ForegroundReadOnlyColor}" />
            <Setter Property="IsHitTestVisible" Value="False" />
        </Style>

    Thanks!
  2. Boris
    Admin
    Boris avatar
    276 posts

    Posted 06 Nov 2014 Link to this post

    Hi George,

    I tried to reproduce the mentioned error, however I was unsuccessful. Could you please edit the attached sample project in a way that it reproduces the issue? In addition from your picture I noticed that the style is applied.

    Regards,
    Boris
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. Michael
    Michael avatar
    7 posts
    Member since:
    Mar 2013

    Posted 20 Apr 2015 in reply to George Link to this post

    Did you ever figure this out? I found that this happens a lot to me but if I restart Visual Studio the errors go away... until after X number of builds they show up again. Frustrating.
  4. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 20 Apr 2015 Link to this post

    Hi Michael,


    Generally errors of this type are raised when you have some type mismatch in a well-formed document. 
    Everything with the provided mark-up is right, you could find more info for these exceptions, here. 
    For the time being I may suggest you to check the type required by the collection once this error occured.
    In addition to this checking the version of all required assemblies for the grid might be of help. 



    Regards,
    Vanya Pavlova
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  5. Michael
    Michael avatar
    7 posts
    Member since:
    Mar 2013

    Posted 21 Apr 2015 in reply to Vanya Pavlova Link to this post

    I'm only adding telerik:gridViewDataColumn to <telerik:RadGridView.Columns>
    The project will build and run despite the errors (which is evidence that they are not really errors). If I close visual studio and reopen it they go away.
  6. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 21 Apr 2015 Link to this post

    Hi Michael,


    You may try to update the ToolBox configurator via the following VS menu option:  Telerik - UI for WPF - "Launch Toolbox configurator".

    Please give it a try and let me know how I could assist you further. 


    Regards,
    Vanya Pavlova
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  7. Michael
    Michael avatar
    7 posts
    Member since:
    Mar 2013

    Posted 21 Apr 2015 in reply to Vanya Pavlova Link to this post

    I'm not sure what you're saying. The tools in the toolbox affect how the xaml code is parsed in the designer?

    I updated it to UI for v.2015.1.401.45 (Dev) [Download] but I'm not sure that wasn't what was already configured. Please see the screenshot I attached to my last post.

  8. Vanya Pavlova
    Admin
    Vanya Pavlova avatar
    2019 posts

    Posted 24 Apr 2015 Link to this post

    Hi Michael,


    I've checked the image attached to the previous post once again. Looking at the errors you are getting I suppose that something went wrong with the assemblies. The mark-up looks correctly defined.    
    Some customers experience problems similar to the yours and this option helped to resolve this problem.

    You could check the following forum thread for further reference. The same is applicable to WPF, as well. 
      
    In order to avoid additional round trips, I believe that the best option would be to try to isolate the problem in a runnable project. It could be attached in a separate support thread and would help us a lot. 



    Regards,
    Vanya Pavlova
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
Back to Top