Skip to content
Advertisement

How do I clear specific columns in DataGrid?

i am using WPF, connected to SQL DataBase via LinqToSql. I have filled DataGrid using ItemsSource.

I would like to clear everything in my DataGrid, except first two rows(ID,first and second name), and Headers ofcourse, by pressing a button. All items i would like to(either set to null or 0) remove, are floats, but I can’t find the right logic to do that.

Here is the picture of my DataGrid–>enter image description here

This is my code behind, and here is Xaml code:

Advertisement

Answer

Change the type of the columns that you want to be able to blank out from float to Nullable<float> (float?) and simply set the properties to null:

You also need to implement the INotifyPropertyChanged interface and raise property change notifications in your data class.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement