C#/WPF - Learning the DataGrid

Поделиться
HTML-код
  • Опубликовано: 20 сен 2024
  • In this live stream I focus on learning the WPF DataGrid control.
    Material Desing in XAML: github.com/Mat...
    Dotnet Templates: github.com/Keb...
    Broadcasted live on Twitch -- Watch live at twitch.keboo.dev
    Search video contents here: github.com/Keb...

Комментарии • 33

  • @willgordon5737
    @willgordon5737 2 месяца назад +1

    Dude just went GODMODE on DataGrid. Now that's what I'm talking about! Thank you!

    • @Kitokeboo
      @Kitokeboo  2 месяца назад +1

      @@willgordon5737 Glad it was helpful. Happy coding

  • @Adam-ce5mq
    @Adam-ce5mq 11 месяцев назад +4

    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.

    • @Kitokeboo
      @Kitokeboo  11 месяцев назад +1

      Thank you for your kind words. Happy coding

  • @MyAutist
    @MyAutist 2 месяца назад +1

    Hi, Kevin! Many thanks! It was very informative.

    • @Kitokeboo
      @Kitokeboo  2 месяца назад

      @@MyAutist Glad it helped. Happy coding!

  • @programmer_rohan
    @programmer_rohan 11 месяцев назад +1

    Thanks!
    You made this video.

  • @joegopher9280
    @joegopher9280 7 месяцев назад +1

    Extremely helpful!

    • @Kitokeboo
      @Kitokeboo  7 месяцев назад +1

      Glad to hear it. Happy coding!

  • @YassinAlHassany
    @YassinAlHassany 11 месяцев назад +1

    Great video. Thanks.
    Can you please explain how to use DataGrid events with MVVM.

    • @Kitokeboo
      @Kitokeboo  11 месяцев назад +2

      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.

    • @YassinAlHassany
      @YassinAlHassany 11 месяцев назад

      @@Kitokeboo highly appreciated. Thanks a lot.

  • @niangel2704
    @niangel2704 8 месяцев назад +1

    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

  • @jakesarkar8929
    @jakesarkar8929 3 месяца назад

    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?

    • @Kitokeboo
      @Kitokeboo  3 месяца назад

      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}"

  • @ColorMyHairIs
    @ColorMyHairIs 10 месяцев назад

    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.

    • @Kitokeboo
      @Kitokeboo  10 месяцев назад +1

      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

  • @markolazar2149
    @markolazar2149 4 месяца назад

    Bless you saaarr!

    • @Kitokeboo
      @Kitokeboo  4 месяца назад

      Thanks! Happy coding

  • @paulakwakernaak2056
    @paulakwakernaak2056 8 месяцев назад

    What about changing the background of the header based on the IsReadOnly property of the cell?

    • @Kitokeboo
      @Kitokeboo  8 месяцев назад

      This was a great question, so I made a video response. ruclips.net/video/qhAHPf7xRdI/видео.html

  • @alexandrufilipescu1301
    @alexandrufilipescu1301 4 месяца назад

    Where can I find your code? Thanks for the video.

    • @Kitokeboo
      @Kitokeboo  3 месяца назад +1

      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.

    • @alexandrufilipescu1301
      @alexandrufilipescu1301 3 месяца назад

      @@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...

  • @darshanpanchal3046
    @darshanpanchal3046 10 месяцев назад

    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

    • @Kitokeboo
      @Kitokeboo  9 месяцев назад

      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.

  • @xarxel5527
    @xarxel5527 9 месяцев назад

    How can i display many-to-many relational data in a DataGrid

    • @Kitokeboo
      @Kitokeboo  9 месяцев назад

      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.

  • @sergeys5270
    @sergeys5270 11 месяцев назад

    wow!

  • @ErcanMutlu-r4x
    @ErcanMutlu-r4x Месяц назад

    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