Search code examples
c#wpfdata-bindingxamldatagrid

WPF DataGrid customization: alignment, scrolling, performance, usability


I develop desktop-based WPF-application, that uses SQL Server 2008 R2 Database and ADO.NET Entity Framework as connection tool between database and application.

In one of the windows, there is a need to show the content of database's table and let user to perform some manipulations, such as add new record to database, edit selected record and delete selected record.

In order to do this I want to use webmail design pattern, in other words, I want that my window looked exactly as Gmail's inbox, where user can choose letter (in my case row with record from DB), click on mail and see its details, click on checkbox will select a row and let user to delete it.

To do this I'm using a DataGrid control via data binding mechanism:

IBindingList Users = ((from d in App.Context.tbl_users
            select new { d.userID, d.userName, d.userPassword }
          ) as IListSource).GetList() as IBindingList;
this.ContentGrid.DataContext = Users;

As result, I get a DataGrid table with data from DB, but I don't know how to:

  1. Let user choose a record by clicking on checkbox and highlight this row
  2. Remove the specifically selected row from DB & DataGrid by clicking on "Delete button"
  3. Set bigger row height/padding to make more clear/air interface

I read a some of the articles, but can't find solution or examples for my question. Please, could you point me to related articles/sites or suggest an example how to implement it?


Solution

  • Normally with DataGrid, clicking on row or the left-hand row-header ("gutter"?) will select the row.

    The user can delete the row by pressing the delete key, or you could do it programmaticly (eg. in a command) by getting the selected item from DataGrid.SelectedItem (or SelectedItems if you enabled multi-selection), then deleting it from your DB.

    For row height, check out DataGrid.RowHeight