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

Way to hide a column?

6 Answers 414 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jonathan Miller
Top achievements
Rank 1
Jonathan Miller asked on 17 Sep 2008, 05:44 PM
I have a dataset that is  a master/detail, displaying as hierchical data.

The 2 tables are joined on a column called "InvoiceID"

I do not want to show the "InvoiceID" column in the detail data

Without defining every column that should be displayed in xaml, is there a way to specify a column that I want to hide?  Thanks

6 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 22 Sep 2008, 09:17 AM
Hello Jonathan ,

Yes , there is a way to show only specific columns from your datatable in the hierarchy child datatable without specifying the column in the XAML. A similar approach is shown in the Hierarchy/TableHierarchy example in our examples application (QSF).

Please take a look at the code of the example. There is a column called 'OrderID' used for the relation without actually showing the column in the UI. I believe the shown approach is similar to what you are up to.

If the example does not help enough let me know so that I can prepare a sample application for you. In this case I will need a few lines from your code (those related to the databinding of the grid) .

Greetings,
Pavel Pavlov
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
jas
Top achievements
Rank 1
answered on 22 Aug 2009, 01:54 PM
Could you please give an actual example, with code, of how to hide columns.

The application you refer to has OrderID fully visible on both levels of the heirarchy!

My grid xaml is:
        <telerik:RadGridView  
            ItemsSource="{Binding Persons}"  
            AutoGenerateHierarchyFromDataSet="True" 
            ShowGroupPanel="False" 
            Grid.Column="1"  
            Grid.Row="2"  
            Margin="10,10,10,10"  
            Name="radGridView1"  
            xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"  
            ClipToBounds="False" /> 
 

Persons is a large object containing collections (e.g. addresses), but I only want to display, on this view, a few columns from it. Which is the best way to do this? [control version is current at Aug'09]

jas

0
ManniAT
Top achievements
Rank 2
answered on 22 Aug 2009, 02:20 PM
Hi,

since you use autogenerated columns the columns "exist" at the moment the data is loaded.
So you should handle the things in the "DataLoaded" event of the RadGridView.
There you can iterate through the columns and set "IsVisible" to false for the columns you want to hide.
A simple example (just hiding the first columns) would look like this:
    private void radGridView1_DataLoaded(object sender, EventArgs e) {  
            radGridView1.Columns[0].IsVisible = false;  
        } 

Regards

Manfred
PS: if this post was helpfull pleas set "Mark as answer"
0
jas
Top achievements
Rank 1
answered on 22 Aug 2009, 02:39 PM
Thanks for the very quick reply!

I am aiming to subscribe to MVVM principles with this design and thus keep the code-behind to a minimum - and have just found a solution in XAML (which is little different from doing it in code-behind, but neater maybe).

In XAML and with AutoGenerateColumns="False" I will just specify the columns needed in this sort of way:
            <telerik:RadGridView.Columns> 
                <telerik:GridViewDataColumn DataMemberBinding="{Binding CName}" Header="Name" /> 
                <telerik:GridViewDataColumn DataMemberBinding="{Binding SName}" Header="Surname" /> 
            </telerik:RadGridView.Columns> 
 
as I only need about four columns from about ten possible.

Regards

James.
ps: can't immediately see how to 'mark as answer' but perhaps it wil lbe apparent when I post this... Nope - I must be blind/stupid - how do I mark your reply thus?
0
ManniAT
Top achievements
Rank 2
answered on 22 Aug 2009, 02:45 PM
OK,

that's different. Your "sample code" showed a grid with autogenerated columns.
And in this case there is no way to do the things declarative.
If you don't need to have autogeneration your solutions is the correct approach of course.
You simply define what you need to display :)

And sorry about the "mark as answer" - since you are not the originator of this thread you can't do it.
I've simply overseen this fact.

Regards

Manfred
0
jas
Top achievements
Rank 1
answered on 22 Aug 2009, 02:51 PM
That explains it!

Cheers,

James.
Tags
GridView
Asked by
Jonathan Miller
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
jas
Top achievements
Rank 1
ManniAT
Top achievements
Rank 2
Share this question
or