Hi Kevin, just wanted to let you know I really enjoyed the video. I appreciated you not only explaining how to implement the DataGrid's various features but also what's going on under the hood, e.g. needing to create a style that targets a TextBlock in standard mode but one which targets a TextBox in editing mode.
Hi, i would like to know how i can change it so when i click on a cell the editMode doesnt immediately start the EditMode but rather gets selected and only on a double click it gets edited
Good question. At its most basic, you can simply leverage your code behind file (*.xaml.cs) to handle generic events and invoke methods on your view model. A common misconception is that you should not use the code behind file. This is incorrect; the code behind file is perfectly acceptable for performing View logic. Business logic should not be put here, but code that is dealing directly with the view is perfectly fine. So it is perfectly acceptable to use it to handle DataGrid events. Depending on the specifics you will find information online where people show using alternate techniques, using Attached Properties, Behaviors, or EventTriggers. These are all fine as well.
Hi Kevin, again this is a precious tutorial re: DataGrid!! I am wondering if you could please teach us on how to call a Community MVVM Toolkit WM's RelayCommand (eg EditUser) when the user DoubleClicks in a row and especially if the user rightclicks in a row and a ContextMenu with "Edit" and "Delete" items popup. It is easy to do that if you make use of the code behind but I find it to be rather impossible to be done directly without the use of it? I drove crazy with all these bindings and I have given up You are my one and only hope as even in StackOverflow I could not find someone that could really help. Also please be aware that I would like all of them to happen when the user double or right clicks ONLY within a row and NOT anywhere else within the datagrid. Of course this could be the theme of anohter short youtube video. And I say "short video" because I am sure that for you this could be a piece of cake Thanx mate and keep on helping us
Hi Kevin, thanks for the video I learnt a lot. I'm struggling to find a way to make the DataGridComboBoxColumn commit changes immediately after selection however, I have a second DataGridComboBoxColumn that is dependent on the selected item in the first. Any pointers?
That is a good question. If you are using the SelectedValueBinding you should just need to change the mode of the binding to be PropertyChanged rather than its default. Something like this: SelectedValueBinding="{Binding Food, UpdateSourceTrigger=PropertyChanged}"
UI becomes laggy after just 50 rows and 10 columns, is there any way to make wpf datagrid fast?, there is option in syncfusion datagrid to "EnableDataVirtualization" and its working, but in wpf any virtualization option is not working
I might need a bit more context on what you have setup. There are several conditions that can disable virtualization (see Displaying Large DataSets here: learn.microsoft.com/en-us/dotnet/desktop/wpf/advanced/optimizing-performance-controls?view=netframeworkdesktop-4.8&WT.mc_id=DT-MVP-5003472). A few key things to check (my preferred way is with Snoop). On your DataGrid, ScrollViewer.CanContentScroll must be True. VirtualizingPanel.IsVirtualizing must be True. DataGrid.EnableRowVirtualization should be True. DataGrid.EnableColumnVirtualization should be True.
It will sort of depends on the context of your application. There is not a good built-in cell type for holding a collection of things. You will likely end up in the template based column. If we imagine a DataGrid of businesses, with a many-to-many relationship with customers. One possible option could show all of the customer names in the view version of the cell, and in the edit version to display all of the customers in a list. Obviously, this will have issues as the number of customers grows. At that point you are likely looking to display the list in a popup or similar. Happy coding.
Unfortunately, it looks like I failed to push this code anywhere and my system has been cleaned since doing this stream, so I think the original copy has been lost.
@@Kitokeboo Oh, thanks anyway. I had issues with "DataGridComboBoxColumn" and ended just avoiding the binding and writing it in xaml. I think that I will use Electron for the next project...
At the 50+ minute mark you talk about the need for the Model and ViewModel to be seperate entities. A few of us have been discussing this same subject. You say that as soon as you have to start adding stuff to your Model for the View, you should wrap it in a ViewModel... I was thinking that when you create the ViewModel for the Model, that you can pass the Model in as a parameter of the ViewModel Constructor. Using Reflection you can match properties in the Model to properties in the ViewModel and pass on the values from the Model to the ViewModel... Would you also recommend having a private field in the ViewModel that represents the Model. I hope that makes sense.
I think a lot depends on your domain and what you are doing. But yes, I think it certainly does make sense for VMs that are essentially representing models. For example, in my SimplyBudget application, I typically store the Primary Key with the view model (but I would have no objection to storing the entire model). You can seen one example of that here: github.com/Keboo/SimplyBudget/blob/main/SimplyBudgetDesktop/ViewModels/AccountViewModel.cs
PLEASE GUYS DO NOT USE 3rd PARTY software to explain software. WE ARE JUST LEANING, MAKE TUTORIALS SIMPLE. I MEAN SIMPLE MEANS JUST DRUG AND DROP DataGrid AND START TUTORIAL. WE DO NOT WANNA SHITTY PLUGUNS MVVMM STAUFF.. WE ARE JUST BEGINNER
Thanks Kevin, you really help me a lot 💜
@@eddahlouliayoub1132 Glad to hear it. Happy coding!
Hi Kevin, just wanted to let you know I really enjoyed the video. I appreciated you not only explaining how to implement the DataGrid's various features but also what's going on under the hood, e.g. needing to create a style that targets a TextBlock in standard mode but one which targets a TextBox in editing mode.
Thank you for your kind words. Happy coding
Dude just went GODMODE on DataGrid. Now that's what I'm talking about! Thank you!
@@willgordon5737 Glad it was helpful. Happy coding
Hi, Kevin! Many thanks! It was very informative.
@@MyAutist Glad it helped. Happy coding!
Hi, i would like to know how i can change it so when i click on a cell the editMode doesnt immediately start the EditMode but rather gets selected and only on a double click it gets edited
Thanks!
You made this video.
Great video. Thanks.
Can you please explain how to use DataGrid events with MVVM.
Good question. At its most basic, you can simply leverage your code behind file (*.xaml.cs) to handle generic events and invoke methods on your view model. A common misconception is that you should not use the code behind file. This is incorrect; the code behind file is perfectly acceptable for performing View logic. Business logic should not be put here, but code that is dealing directly with the view is perfectly fine. So it is perfectly acceptable to use it to handle DataGrid events.
Depending on the specifics you will find information online where people show using alternate techniques, using Attached Properties, Behaviors, or EventTriggers. These are all fine as well.
@@Kitokeboo highly appreciated. Thanks a lot.
Extremely helpful!
Glad to hear it. Happy coding!
Hi Kevin, again this is a precious tutorial re: DataGrid!! I am wondering if you could please teach us on how to call a Community MVVM Toolkit WM's RelayCommand (eg EditUser) when the user DoubleClicks in a row and especially if the user rightclicks in a row and a ContextMenu with "Edit" and "Delete" items popup. It is easy to do that if you make use of the code behind but I find it to be rather impossible to be done directly without the use of it? I drove crazy with all these bindings and I have given up You are my one and only hope as even in StackOverflow I could not find someone that could really help. Also please be aware that I would like all of them to happen when the user double or right clicks ONLY within a row and NOT anywhere else within the datagrid.
Of course this could be the theme of anohter short youtube video. And I say "short video" because I am sure that for you this could be a piece of cake Thanx mate and keep on helping us
What about changing the background of the header based on the IsReadOnly property of the cell?
This was a great question, so I made a video response. ruclips.net/video/qhAHPf7xRdI/видео.html
Hi Kevin, thanks for the video I learnt a lot. I'm struggling to find a way to make the DataGridComboBoxColumn commit changes immediately after selection however, I have a second DataGridComboBoxColumn that is dependent on the selected item in the first. Any pointers?
That is a good question. If you are using the SelectedValueBinding you should just need to change the mode of the binding to be PropertyChanged rather than its default. Something like this: SelectedValueBinding="{Binding Food, UpdateSourceTrigger=PropertyChanged}"
UI becomes laggy after just 50 rows and 10 columns, is there any way to make wpf datagrid fast?, there is option in syncfusion datagrid to "EnableDataVirtualization" and its working, but in wpf any virtualization option is not working
I might need a bit more context on what you have setup. There are several conditions that can disable virtualization (see Displaying Large DataSets here: learn.microsoft.com/en-us/dotnet/desktop/wpf/advanced/optimizing-performance-controls?view=netframeworkdesktop-4.8&WT.mc_id=DT-MVP-5003472).
A few key things to check (my preferred way is with Snoop). On your DataGrid, ScrollViewer.CanContentScroll must be True. VirtualizingPanel.IsVirtualizing must be True. DataGrid.EnableRowVirtualization should be True. DataGrid.EnableColumnVirtualization should be True.
How can i display many-to-many relational data in a DataGrid
It will sort of depends on the context of your application. There is not a good built-in cell type for holding a collection of things. You will likely end up in the template based column.
If we imagine a DataGrid of businesses, with a many-to-many relationship with customers. One possible option could show all of the customer names in the view version of the cell, and in the edit version to display all of the customers in a list. Obviously, this will have issues as the number of customers grows. At that point you are likely looking to display the list in a popup or similar.
Happy coding.
Where can I find your code? Thanks for the video.
Unfortunately, it looks like I failed to push this code anywhere and my system has been cleaned since doing this stream, so I think the original copy has been lost.
@@Kitokeboo Oh, thanks anyway. I had issues with "DataGridComboBoxColumn" and ended just avoiding the binding and writing it in xaml. I think that I will use Electron for the next project...
At the 50+ minute mark you talk about the need for the Model and ViewModel to be seperate entities. A few of us have been discussing this same subject. You say that as soon as you have to start adding stuff to your Model for the View, you should wrap it in a ViewModel... I was thinking that when you create the ViewModel for the Model, that you can pass the Model in as a parameter of the ViewModel Constructor. Using Reflection you can match properties in the Model to properties in the ViewModel and pass on the values from the Model to the ViewModel... Would you also recommend having a private field in the ViewModel that represents the Model. I hope that makes sense.
I think a lot depends on your domain and what you are doing. But yes, I think it certainly does make sense for VMs that are essentially representing models. For example, in my SimplyBudget application, I typically store the Primary Key with the view model (but I would have no objection to storing the entire model). You can seen one example of that here: github.com/Keboo/SimplyBudget/blob/main/SimplyBudgetDesktop/ViewModels/AccountViewModel.cs
Bless you saaarr!
Thanks! Happy coding
wow!
PLEASE GUYS DO NOT USE 3rd PARTY software to explain software. WE ARE JUST LEANING,
MAKE TUTORIALS SIMPLE. I MEAN SIMPLE MEANS JUST DRUG AND DROP DataGrid AND START TUTORIAL.
WE DO NOT WANNA SHITTY PLUGUNS MVVMM STAUFF.. WE ARE JUST BEGINNER