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

How to display column only when data available?

1 Answer 63 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Andreas
Top achievements
Rank 1
Andreas asked on 04 Sep 2010, 09:47 AM
Hi guys.

What would be the best way in xaml to display a RadGridViewColumn only when data is available
e.g.
I have to column in my Radgridview. These columns are binding against an IEnumerable List of Materials (Type: MATERIAL)

If one column doesn not contain any data in all underlying rows, i would like not to display this column. (i only want to display columns with cell values)
How can this be done?
thanks for your help
<DataTemplate>
    <tcg:RadGridView x:Name="RadGridView1" CanUserFreezeColumns="False" AutoGenerateColumns="False" ItemsSource="{Binding MBEP}"  ShowGroupPanel="False" IsReadOnly="True">
        <tcg:RadGridView.Columns            
                <tcg:GridViewDataColumn DataMemberBinding="{Binding MATERIAL.Txt1}" Header="Material Descr."/>
                <tcg:GridViewDataColumn DataMemberBinding="{Binding MATERIAL.MatNr}" Header="Material No" Width="{Binding MATA.MatNr.Length}"/>
        </tcg:RadGridView.Columns>
    </tcg:RadGridView>
</DataTemplate>

1 Answer, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 06 Sep 2010, 04:10 PM
Hello Thomas Roithmeier,

You can subscribe to DataLoaded event and try something like that:

void gridView_DataLoaded(object sender, EventArgs e)
{
    var allValuesForProperty1AreNull = false;
    var allValuesforProperty2AreNull = false;
  
    foreach (Material material in this.gridView.Items)
    {
        allValuesForProperty1AreNull |= material.Property1
        allValuesForProperty2AreNull |= material.Property2
    }
  
    if (allValuesForProperty1AreNull)
        ; // remove first column
  
    if (allValuesForProperty2AreNull)
        ; // remove second column
}


Best wishes,
Milan
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
GridView
Asked by
Andreas
Top achievements
Rank 1
Answers by
Milan
Telerik team
Share this question
or