[Solved] I like to hide a column in DataGrid

1 Answer 14 Views
DataGrid
Hardy
Top achievements
Rank 1
Hardy asked on 16 Feb 2026, 09:26 AM
// Spalten, die ausgeblendet werden sollen
            var zuVersteckendeSpalten = new[] { "AssetObjectId", "Id", "Media", "TheGeom" };

            foreach (var col in dataGrid.Columns)
            {
                if (zuVersteckendeSpalten.Contains(col.Name))
                {
                    col.IsVisible = false;
                }
            }

1 Answer, 1 is accepted

Sort by
0
Didi
Telerik team
answered on 16 Feb 2026, 02:36 PM

Hello Hardy,

You can hide the columns using the code you paste. Here is my test scenario:

    <Grid Padding="16" RowSpacing="12" RowDefinitions="Auto,*">

        <Button Text="Hide Email Column"
                Clicked="OnHideEmailClicked" />
        <telerik:RadDataGrid x:Name="DataGrid" Grid.Row="1"
                              ItemsSource="{Binding Items}"
                              AutoGenerateColumns="False"
                              UserEditMode="Cell">
            <telerik:RadDataGrid.Columns>
                <telerik:DataGridTextColumn HeaderText="Name" PropertyName="Name" />
                <telerik:DataGridNumericalColumn HeaderText="Age" PropertyName="Age" />
                <telerik:DataGridTextColumn x:Name="EmailColumn" HeaderText="Email" PropertyName="Email" />
            </telerik:RadDataGrid.Columns>
        </telerik:RadDataGrid>

    </Grid>

the model and view model:

public class Person
{
    public string Name { get; set; } = string.Empty;
    public int Age { get; set; }
    public string Email { get; set; } = string.Empty;
}
public class MainViewModel
{
    public ObservableCollection<Models.Person> Items { get; } = new()
    {
        new Models.Person { Name = "Alice", Age = 30, Email = "alice@example.com" },
        new Models.Person { Name = "Bob", Age = 25, Email = "bob@example.com" },
        new Models.Person { Name = "Charlie", Age = 35, Email = "charlie@example.com" }
    };
}

 

and the code for hiding columns email and age on button click:

private void OnHideEmailClicked(object sender, EventArgs e)
{
    var zuVersteckendeSpalten = new[] { "Id", "Age", "Email" };
    foreach (var column in this.DataGrid.Columns)
    {
        if(zuVersteckendeSpalten.Contains(column.HeaderText))
        {
            column.IsVisible = false;
        }
    }
}

Hope this helps.

Regards,
Didi
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Hardy
Top achievements
Rank 1
commented on 18 Feb 2026, 03:44 PM

Hi Didi,

sorry but that doesn't work.

I think it's because I'm using a DataSource at runtime

var kontrollEintraege = dbService.LadeKontrollEintraegeZuAssetObject(eintrag.Id);

dataGrid.ItemsSource = kontrollEintraege;

Do I have to define the columns in XAML?

Regards Hardy

Lance | Senior Manager Technical Support
Telerik team
commented on 18 Feb 2026, 05:21 PM

Hi Hardy,

Thank you for clarifying that you are using automatic column generation. You don't have to manually define them in order to hide a column, you just need to make sure you wait until all the columns are finished being generated before you try it.

For example, instead of a button click like Didi shows, you could try the Columns' CollectionChanged event (Columns is an ObservableCollection):

dataGrid.Columns.CollectionChanged += (s, e) =>
{
    foreach (var column in dataGrid.Columns)
    {
        if (zuVersteckendeSpalten.Contains(column.HeaderText))
            column.IsVisible = false;
    }
};

Recommendation

If you want a predicable column set, and lifecycle timing reliability, I would highly recommend manually defining the columns you want to show. This has many additional benefits, including setting the column type, sorting/filtering properties, visual layout, and more.

While setting this up in XAML is a lot easier and faster to manage, you don't have to. If you prefer C#, it is the same idea. Here's an example based on your provided code

var dataGrid = new RadDataGrid();

// Turn off automatic column generation
dataGrid.AutoGenerateColumns = false;

// Define the columns you want to see
// Check out all the column types and customization options in the documentation: https://docs.telerik.com/devtools/maui/controls/datagrid/columns
dataGrid.Columns.Add(new DataGridTextColumn{ PropertyName = "MyTextProperty" });
dataGrid.Columns.Add(new DataGridTextColumn { PropertyName = "MyBoolProperty" });
dataGrid.Columns.Add(new DataGridTextColumn { PropertyName = "MyDateProperty" });


// // Make sure this is set last
var kontrollEintraege = dbService.LadeKontrollEintraegeZuAssetObject(eintrag.Id);
dataGrid.ItemsSource = kontrollEintraege;

Tags
DataGrid
Asked by
Hardy
Top achievements
Rank 1
Answers by
Didi
Telerik team
Share this question
or