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 lastvar kontrollEintraege = dbService.LadeKontrollEintraegeZuAssetObject(eintrag.Id);
dataGrid.ItemsSource = kontrollEintraege;