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

GridViewDataColumn = Nothing in code behind?

2 Answers 99 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Rob Ainscough
Top achievements
Rank 1
Rob Ainscough asked on 23 Jul 2012, 06:21 PM
This has to be something simple I'm missing.

I have a UserControl with a Telerik RadGridView:

<telerik:RadGridView x:Name="MerchandiseGridView" Margin="0"
            AreRowDetailsFrozen="True"
            AutoGenerateColumns="False"
            CanUserFreezeColumns="False"
            CanUserReorderColumns="False"
            CanUserResizeColumns="False"
            CanUserSortColumns="False"
            RowIndicatorVisibility="Collapsed"
            DataContext="{Binding Source={StaticResource MerchandiseData}}"
            ItemsSource="{Binding Collection}"
            ShowGroupPanel="False" IsReadOnly="False" IsFilteringAllowed="True">
            <telerik:RadGridView.Columns>
 
                <!-- (0) Merchandise ID -->
                <telerik:GridViewDataColumn x:Name="MerchandiseIDColumn" Header="MerchandiseID" IsVisible="False" DataMemberBinding="{Binding MerchandiseIDID}" />
                <!-- (1) Select for Merchandise Returns -->
                <telerik:GridViewDataColumn x:Name="MerchandiseSelectColumn" Header="" DataMemberBinding="{Binding Selected}" IsReadOnly="True" IsVisible="False">
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <CheckBox IsChecked="{Binding Selected, Mode=TwoWay}" />
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
                </telerik:GridViewDataColumn>
                <!-- (2) Type of Merchandise -->
                <telerik:GridViewDataColumn x:Name="MerchandiseTypeColumn" Header="Type" IsReadOnly="True" Width="110" DataMemberBinding="{Binding Type}" />
                <!-- (3) Item -->
                <telerik:GridViewDataColumn x:Name="MerchandiseItemColumn" Header="Item" IsReadOnly="True" Width="190" DataMemberBinding="{Binding Item}" />
                <!-- (4) Part Number -->
                <telerik:GridViewDataColumn x:Name="MerchandisePartNoColumn" Header="Part No." IsReadOnly="True" Width="100" IsVisible="True" DataMemberBinding="{Binding PartNumber}" />
                <!-- (5) Price -->
                <telerik:GridViewDataColumn x:Name="MerchandisePriceColumn" Header="Price" IsReadOnly="True" Width="70" DataMemberBinding="{Binding Price}" TextAlignment="Right" />
 
            </telerik:RadGridView.Columns>
 
        </telerik:RadGridView>

In my code-behind this works:
Me.MerchandiseGridView.Columns(0).IsVisible = True

In my code-behind this DOES NOT work (get instance not set error):
Me.MerchandiseSelectColumn.IsVisible = True

SL5 project .NET 4.0

Any suggestions why this doesn't work?

Thanks, Rob.

2 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 23 Jul 2012, 06:29 PM
Hello Rob,

Actually, setting Name attribute to a column is not appropriate since it is not a visual element. You can set its UniqueName property instead. However, if you want to work with it, you need first to find it in the Columns collection either by its index (Columns[0]) or by its UniqueName (Columns["MyColumnName"]). 

All the best,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Rob Ainscough
Top achievements
Rank 1
answered on 23 Jul 2012, 07:53 PM
Maya,

Many thanks once again for a prompt answer.  UniqueName is working for me - thank you!

On a side note: Silverlight and XAML often make little to no sense to me with the redundant elements that can be used and referenced, but do nothing.  For example, I would assume that an objects "visual" significance is not relevant to the code-behind access to that object -- so what if it's not a visual element, I still want to reference it in a manor consistent with other elements. 

And further more, there is nothing clearly obvious that GridViewDataColumn is not a visual element.  SL5 and XAML just seem so arbitrary and far from consistant intuitive flow like one would expect from Windows Forms application.  It seems very dependant on rules that are not obvious or intuitive.

It baffles me how SL5 or even HTML5 survive with such non-intuitive concepts.  I'm starting to get used to it, but it really boggles my mind on how SL5 constructs work and the endless methods and properties that exist but should never be used.

Rob.
Tags
GridView
Asked by
Rob Ainscough
Top achievements
Rank 1
Answers by
Maya
Telerik team
Rob Ainscough
Top achievements
Rank 1
Share this question
or