Logo video2dn
  • Сохранить видео с ютуба
  • Категории
    • Музыка
    • Кино и Анимация
    • Автомобили
    • Животные
    • Спорт
    • Путешествия
    • Игры
    • Люди и Блоги
    • Юмор
    • Развлечения
    • Новости и Политика
    • Howto и Стиль
    • Diy своими руками
    • Образование
    • Наука и Технологии
    • Некоммерческие Организации
  • О сайте

Скачать или смотреть How to Delete Rows from a Data Grid

  • Brian Lagunas
  • 2020-11-02
  • 13966
How to Delete Rows from a Data Grid
delete rows from a data griddelete rows from a data grid in WPFdelete rows from a data grid in WPF using MVVMdelete rows mvvmc# datagridview delete row buttondelete selected row in datagridview c#datagridview delete row c#datagridview delete rowshow to delete selected row in gridview using c#delete datagridview rowdatagridview delete rowc# delete gridview rowc# datagridviewmvvm delete rows data griddelete selected rows mvvmdelete rows
  • ok logo

Скачать How to Delete Rows from a Data Grid бесплатно в качестве 4к (2к / 1080p)

У нас вы можете скачать бесплатно How to Delete Rows from a Data Grid или посмотреть видео с ютуба в максимальном доступном качестве.

Для скачивания выберите вариант из формы ниже:

  • Информация по загрузке:

Cкачать музыку How to Delete Rows from a Data Grid бесплатно в формате MP3:

Если иконки загрузки не отобразились, ПОЖАЛУЙСТА, НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если у вас возникли трудности с загрузкой, пожалуйста, свяжитесь с нами по контактам, указанным в нижней части страницы.
Спасибо за использование сервиса video2dn.com

Описание к видео How to Delete Rows from a Data Grid

In this video, I show you how to delete rows from a data grid in WPF using MVVM.

The ability to delete rows from a data grid in WPF using MVVM is a core scenario in just about every WPF application in existence. It's so common, that you would think this feature would be built into the standard WPF data grid control, but it's not. This means you are forced to implement this behavior yourself. Luckily, it's really easy to delete rows from a data grid in WPF. In this video, I'll show you how using the MVVM pattern.

The first step to delete rows from a data grid in WPF using MVVM is to add a delete button that will actually delete the row from the data grid. You have a couple of options here. You can place a single delete button on the same form as the data grid, and when you click the button it will delete the selected item from the data grid. Another option is to place a delete button on every row of the grid, and then when you click the delete button, it will delete the row in the data grid for that specific row only.

In this video I will add a delete button to each row but adding a DataGridTemplateColumn to the data grid. I will then create a data binding on the button's Command property to an ICommand called DeleteCommand that will remove the person from the data grid's ItemsSource (in this case a property called People) which in turn will delete the row from the data grid. The command looks something like this:

private DelegateCommand[Person] _deleteCommand;
public DelegateCommand[Person] DeleteCommand =]
_deleteCommand ?? (_deleteCommand = new DelegateCommand[Person](ExecuteDeleteCommand));

void ExecuteDeleteCommand(Person parameter)
{
People.Remove(parameter);
}

Note: Angle brackets are not allowed in YouTube descriptions. They have been replaced with []

This is where I see the biggest MVVM mistake made. At this point, most people will create a new ViewModel that represents a row in the data grid. Then they will have a collection of ViewModel, for example a PersonViewModel, to populate the data grid. DON'T DO THIS!!! Instead we are going to define our command in the MainWindowViewModel. Then we simply modify the Command binding to use the ICommand defined on the MainWindowViewMode instead. The button will look something like this:

Button Command="{Binding DataContext.DeleteCommand, ElementName=_window}" CommandParameter="{Binding}"

This assumes you have given your Window an x:Name="_window".

This will tell the button to use the DeleteCommand that we defined on our MainWindowViewModel and passes the current Person (the row's data context) as the Command Parameter.

Run the application, and you can now delete rows from a data grid in WPF using MVVM.

Be sure to watch my new Pluralsight course "Introduction to Prism for WPF":
https://pluralsight.pxf.io/bE3rB

Sponsor Me:
https://github.com/sponsors/brianlagunas

Follow Me:
Twitter:   / brianlagunas  
Twitch:   / brianlagunas  
Blog: http://brianlagunas.com
GitHub: https://github.com/brianlagunas

Комментарии

Информация по комментариям в разработке

Похожие видео

  • О нас
  • Контакты
  • Отказ от ответственности - Disclaimer
  • Условия использования сайта - TOS
  • Политика конфиденциальности

video2dn Copyright © 2023 - 2025

Контакты для правообладателей [email protected]