Click here to Skip to main content
15,893,161 members
Everything / DataGrid

DataGrid

DataGrid

Great Reads

by xllance
An approach to bind datagrids through ITypedList interface.
by Shenwei Liu
A custom and configurable Angular data grid tool and demo application presenting both client and server-side data filtering, sorting, and pagination (updated to Angular 11)
by chuck in st paul
This is a utility program for bulk/batch renaming of files that demonstrates using and creating events
by Frank Augustin
Describe validation when presenting data in WPF Toolkit’s DataGrid.

Latest Articles

by Peter Huber SG
A deep dive into how to easily display data exactly the way you want when DataGrid is not up to the task
by Shenwei Liu
Implementing and describing multiple column sorting features with the Angular data grid tool NgExTable and associated processing logic for sorting the source data list (updated to Angular 11)
by Shenwei Liu
A custom and configurable Angular data grid tool and demo application presenting both client and server-side data filtering, sorting, and pagination (updated to Angular 11)
by Vassili Kravtchenko-Berejnoi
A generic workaround for auto-generating multiple custom columns in a WPF DataGrid in case where the data class has multiple properties of the same type

All Articles

Sort by Updated

DataGrid 

19 Mar 2024 by Graeme_Grant
I am not sure what you are trying to do however I'll show you how to handle each item in the ObservableCollection. The Item class needs to implement the INotifyPropertyChanged Interface (System.ComponentModel)[^]. Microsoft provide a sample: How...
17 Mar 2024 by Pete O'Hanlon
You cannot tell if an object has been changed using an ObservableCollection. The way to do this is to use INotifyPropertyChanged and raise the PropertyChanged event whenever you change the value in a property.
17 Mar 2024 by Sh.H.
Hi folks. I have an Observation Collection. I used event CollectionChanged. But this event only raises when new item added, or an item deleted. So how can I detect if an item edited? (And ofcourse, it would better also to detect which item got...
16 Feb 2024 by Andre Oosthuizen
Gerry gave the solution, to elaborate on taht - The TextBlock is a read-only control, and that's why you can't edit the content when you double-click on it - MS Learn | TextBlock Class[^] To use editing, you should use an editable control such...
16 Feb 2024 by 4711a
I have a DataGrid with a DataGridTemplateColumn. I'm not able to edit the Comment field. When I double click on a Comment field, the background changes a expected to LightSalmon and the content of the bound property Comment is shown but I cannot...
12 Feb 2024 by George Swan
It seems to me that your problem here is in this line of code: TypeofRest = g.Select(x => x.TypeofRest), Result = g.Select(x => x.Result) }) The Select method returns an IEnumerable so both TypeofRest and Result are both IEnumerables. The...
11 Feb 2024 by Max Speed 2022
Hello experts I have a query and everything in my query works well without the last condition, I use the last condition to filter the joined tables, but I get this error: Operator == cannot be applied to operands of type IEnumerable and...
11 Feb 2024 by Maciej Los
Please, read this: Compiler Error CS0019 - C# | Microsoft Learn[^]
15 Jan 2024 by Graeme_Grant
Further to Jo's answer, yes, the article link he has pointed you to does not give you the exact answer that you want however it does show you how to animate. The same principle applies. You need to take that and write the code or use the answer...
14 Jan 2024 by Graeme_Grant
Best place to understand a WPF control is to look at the Default Template. For the DataGrid it can be found here: DataGrid Styles and Templates - WPF .NET Framework | Microsoft Learn[^]. What you are pointing to is the Select All button in the...
14 Jan 2024 by Sh.H.
Hi guys Please kindly see the picture Intersection — Freeimage.host[^] As you see there is a white space between RowHeaders and ColumnHeaders in DataGrid. So I need to know how may I change its color? Thanks. What I have tried: I tried to...
14 Jan 2024 by Jo_vb.net
I searched CodeProject articles... Animation using Storyboards in WPF[^] This may help you to write the code for your own needs.
14 Jan 2024 by Sh.H.
Hi people. Follow my previous post in How do I add new row in datagrid in WPF?[^] I need to know how may I use animation when a row adds or inserts into this DataGrid? I mean when I add or insert new row, it opens like curtain... or accordion....
12 Nov 2023 by Muhammad Usman Apr2022
Hi there! I want to create syncfussion datagrid fully dynamically in Blazor. I'm trying to create a dynamic class that creates properties at runtime instead of hard-coded properties. Please guide me on how can I do that. What I have tried: What...
12 Nov 2023 by M Imran Ansari
You can visit the following link for dynamic columns generation in datagrid using syncfusion: Columns in Blazor DataGrid Component | Syncfusion[^] Here is the sample, download this sample as a demonstration and customize it according to your...
25 Oct 2023 by Matt T Heffron
The only (that I can think of) way to have a variable number of pieces of a text column in different colors (based on two independent values) is to extend the TextBlock control to self-construct its content. Here's what I've done. using...
6 Oct 2023 by Varsha Ramnani
I want to highlight Row & Columns whose Cell is hovered in WPF DataGrid. I have selection Unit of DataGrid Set to Cell. I have not used RowStyle & ColumnStyle just using CellStyle, I have set the RowBackground to transparent. How to accomplish...
31 Jul 2023 by OriginalGriff
Repost: Deleted. Please do not repost your question; use the Improve question widget to add information or reformat it, but posting it repeatedly just duplicates work, wastes time, and annoys people. I'll delete this one.
27 Jul 2023 by Andre Oosthuizen
Based on the links given by Graeme (you should read an entire tutorial, not just the top part), use an 'if' statement to check if there are any employees added to the list, if not your index will be '0', if there are, count the items and add 1 to...
16 Jul 2023 by Sh.H.
Hi guys. When I click on empty part of datagrid, it adds new line to enter new data. So I need to change the first value as automated number as index of datas. I mean for example if the datagrid has 2 lines of datas, when adding new line, the...
16 Jul 2023 by Graeme_Grant
This is a very common task that can be answered via a Google Search: wpf tutorial datagrid edit - Google Search[^] There are many answers and YouTube videos that discuss how to do this. Here are some: * How to - Implement editing functionality...
16 Jul 2023 by Ralf Meier
for to be able to answer your question it's necessary to privide more info (as allready mentioned by me). But to your Code-Snippet : Inside a List of whatever there is NO index -1. You try to assign the index -1 to the index 0 from your List !!!...
25 Jun 2023 by Sh.H.
I guys. How can I make a table in WPF VB.NET? I searched a lot in the web, but I can't find a good answer. What I have tried: I thought to add a table, I should use Datagrid. Datagrid is perfect answer if I use in WindowsForm. But obviously bad...
25 Jun 2023 by RickZeeland
Take a look at Galador.ExcelGrid on GitHub written by our distinguished CodeProject member Super Lloyd. Although it is written in C#, you can probably use the dll in your VB.NET project.
24 Jun 2023 by Sh.H.
I wrote a simple wpf datagrid. So when I double click on a cell, the program crashes. I should add that I checked this post: https://stackoverflow.com/questions/19334326/wpf-datagrid-edititem-is-not-allowed-for-this-view-exception[^] But there...
24 Jun 2023 by Richard MacCutchan
This is the same issue as you already posted at Error on double click on datagrid in WPF VB.NET[^]. I have just built the program from your original code, and the corrections provided by @RichardDeeming, and it works correctly. If you still have...
20 Jun 2023 by Richard Deeming
I was able to reproduce the problem. As far as I can see, it's due to the fact that you're adding items directly to the DataGrid's Items collection. If I change your code to add the employee to a List(Of Employee) instead, and assign that list...
20 Jun 2023 by cmarcotte
According to this page : Specify the Edit Mode for DataGridView Control - Windows Forms .NET Framework | Microsoft Learn[^] You must have Quote: The ReadOnly properties of the cell, row, column, and control are all set to false.
20 Jun 2023 by LiterallyGutsFromBerserk
Hello everyone, I have a datagridview with three columns where, everytime I only have one value, I want to merge my columns, similarly to the picture below : enter image description here I have made sure to have my three column values for each...
20 Jun 2023 by OriginalGriff
See here: How to Merge Cells in DataGridView | 10Tec[^] And do yourself two favours: 1) Indent your code! It's a whole load more readable for everybody if you do, and VS will auto indent it to your preferred style for you. 2) Don't swallow...
19 Jun 2023 by Graeme_Grant
When having issues like these, it is always a good idea to create a test project and check what is happening. Excel Interop - Microsoft Learn[^] especially. So, I have created a spreadsheet manually and put a numeric value in a cell. Then I...
19 Jun 2023 by LiterallyGutsFromBerserk
I am making a Winform application where I export my datagridview to excel. However, when I do it, it doesn't retain the formatting,despite the existence of a line to do so. Here is my code : string fileName; SaveFileDialog saveFileDialog1...
19 Jun 2023 by Richard Deeming
Quote: worksheet.Cell(i + 14, j + 1).Value = dataGridView2.Rows[i].Cells[j].Value?.ToString(); ... worksheet.Cell(i + 14, j + 1).AddConditionalFormat().WhenLessThan(1).Fill.SetBackgroundColor(xlColor); You're setting all of the cells to...
2 May 2023 by OriginalGriff
Repost: Deleted. Please do not repost your question; use the Improve question widget to add information or reformat it, but posting it repeatedly just duplicates work, wastes time, and annoys people. I'll delete this one.
2 May 2023 by Graeme_Grant
When I hit an issue, sometimes I like to remove the noise and break out a small project that focuses on the main issue. I have done just that for you. Start a new WPF project with the name WpfDataGridComboBox and drop this code in and you can...
2 May 2023 by mojtabahakimian
Project subject: I had an MS Access 2003 adp VBA project that would connect to SQL Server Database, Now I'm converting that project to C# WPF, and I'm going to save data directly into SQL Server database from DataGrid in C# WPF Detail: I have...
28 Mar 2023 by Member 14973663
Hello, I have a WPF app that manages people data. Each person has some attributes and a list of phone numbers. In the main window I have a DataGrid bound to a ObservableCollection, with the individual properties in a few DataGridTextColumn, and...
17 Mar 2023 by Graeme_Grant
With data-binding, you need to implement the PropertyChangedEventHandler to notify the data-binding which property has changed. Here is a base class implementation: public abstract class ObservableObject : INotifyPropertyChanged { protected...
16 Mar 2023 by huynhminh97
I have a DataGrid with 2 column: checkbox column and Permission column. In new mode, when users select checkbox All in header then all child's checkbox is selected and vice versa (This logic is woking now). In edit mode, application will check if...
27 Feb 2023 by divya danduprolu
grid onrowediting and onrowdeleting
27 Feb 2023 by devbtl
What are the events for Datagridview row edit,update,cancel,delete action ?Please paste some piece of code :-)
13 Feb 2023 by Grant Mc
Hi. Lets say I have a collection called Orders, and one of the members in the collection, is another collection called Products. So if I have an order, say ID = 001, and it has two different products, I would like to show this on a DataGrid,...
13 Feb 2023 by Grant Mc
OK, still working through this, but here is what I have so far. public partial class MainWindow : Window { MovieCollectionViewModel movieCollection; ObservableCollection actors; public MainWindow() { ...
12 Feb 2023 by Graeme_Grant
This link will show you how: DataGrid with row details - The complete WPF tutorial[^] Here is a little demo with Order > Product grouped data structure: public partial class MainWindow : Window { public MainWindow() { ...
6 Feb 2023 by Max Speed 2022
hi,i joined 2x tables together and bound the items to my datagrideview(membersdataGrid),and thats worked but i can't reach id or anything else in my datagrid here is my code private void Load() { var st = (from s in...
6 Feb 2023 by Richard Deeming
You've created an anonymous type[^] to represent the projection. There is generally no way to cast that to an object and read its properties short of reflection. One simple but fragile approach would be to use C#'s dynamic type[^], which will...
3 Feb 2023 by Member 15758581
I want to add a filtering-function to my (WPF) program. My problem isn that i don't know how i could find specific Items/Objects (DataGridTextColumns) from the DataGrid. I want to search for specific properties like as an example if my object...
3 Feb 2023 by OriginalGriff
Start here: How to: Group, sort, and filter Data in the DataGrid control - WPF .NET Framework | Microsoft Learn[^]
27 Jan 2023 by NIkradsystem
Dear Experts.I write windows application with "VS2010" that bind "SQLServer 2008".I use "DataSource Wizard" to manipulate DataSet,BindingSource,TableAdapter,BindaingNavigator and also DataGridView.I have a "Table" named Sample in my "Database".A one of it's filed has "DateTime" datatype....
10 Jan 2023 by pitwi
I've read a lot about column format of WPF DataGrid but couldn't find a solution for number format. What I have so far is a SQLite database and some lines of code that works fine - except number format. What I want is 2 numbers after the decimal...
10 Jan 2023 by Graeme_Grant
Using XAML rather than code is a far easier way of working with controls including the DataGrid. Here is an example of an answer to an older question with a similar question. Create a new project called WpfDataGridDateColumnFormatting and drop...
9 Jan 2023 by mojtabahakimian
I'm using C# WPF , I have a DataGrid that is bound to an ObservableCollection , I want to keep focus on DataGrid's row when user is entering value with keyboard on DataGrid, I mean when last row is focus after value entered , istead of lost focus...
7 Jan 2023 by mojtabahakimian
I use C# WPF, I am programming an accounting program with a SQL Server database, in this accounting program, data is inserted, updated, and deleted by the user directly in a data grid, which contains a textbox and Combobox elements. In an issue...
7 Jan 2023 by Graeme_Grant
Databinding with data models bound to the DataGrid. EntityFramework or Dapr is a cleaner and simpler database framework. There are plenty of Google searchable tutorials explaining how to do both.
4 Jan 2023 by Graeme_Grant
I wanted to give you a link to a simple solution. This turned out not possible to do. So I have adapted a solution from the following links: * Drag and Drop DataGrid Row in WPF[^] = initial attempt - not a good solution for any Drag'n'Drop! *...
4 Jan 2023 by Member 15639943
Hi everybody: I'm following the drag and drop example: https://www.c-sharpcorner.com/UploadFile/raj1979/drag-and-drop-datagrid-row-in-wpf/ but sometimes using the scrollbar (horizontal or vertical) causes me problems. I am not using the data...
4 Jan 2023 by Member 15639943
I am practicing with datagrid, when I have many rows, the vertical scrollbar is activated. How to know that I am moving the scrollbar button from top to bottom with the left mouse button? Happy new year everybody. What I have tried: I'm new...
4 Jan 2023 by Graeme_Grant
Further to Gerry's solution link, I am expecting you to ask how to get the visible Rows. Here is a solution from Wpf DataGrid: how to detect the set of visible cells? [^] Wire up the event:
4 Jan 2023 by Graeme_Grant
Your outputColumns class does not have a collection to track the selections in the ComboBox (for each row), rather you only have a global collection (for all rows) on the ViewModel. This is why all rows show the same selections in the ComboBoxes....
4 Jan 2023 by EstKells
I have an an DataGrid in which I load Data from an ObservableCollection and each row has an CheckBox so that I can have a list of checked Rows. Now I wanted to add an new Column to the DataGrid which is an ComboBox and in the ComboBox is a list...
31 Dec 2022 by Graeme_Grant
As I am unfamiliar with how to print a Datagrid using ProtDocument, I did a quick google search: c# print datagridview using printdocument - Google[^]and there were lots of solutions - first 3 results: * C# DataGridView Printing[^] * How To...
20 Dec 2022 by Member 15639943
Hello to all the friends of the forum: I have the following code in a purchase datagrid, where the trigger is activated if the purchase date field is blank, color the corresponding row with an alert color. ...
20 Dec 2022 by Member 15639943
I'll try it, thanks for the tip.
20 Dec 2022 by Graeme_Grant
You may need to use a IValueConverter[^] and return a value that the DataTrigger will recognize - in your case, an empty string.
5 Oct 2022 by BabyHai
I am new to WPF development. I've referred to many solutions online but still have no idea. I have a Listbox and a Datagrid. The Listbox loads data and displays selectable items dynamically. The Datagrid shows static table with a checkbox column....
4 Oct 2022 by Gerry Schmitz
The rows / columns of the DataGrid are binding to ExcelDataEntry ... That's where you implement INotifyPropertChanged for the "data items in your data source". When an ExcelDataEntry item is changed, you call "its" OnPropertyChanged handler. If...
6 Sep 2022 by Robert S4r
After frequent search on almost all sites, I've failed to get a solution to the problem. My datagrid is bound to SQL server database using entity framework hence no MVVM pattern. The copy from datagrid seems to work with a few codes (seems...
6 Sep 2022 by Robert S4r
After frequent search on almost all sites, I've failed to get a solution to the problem. My datagrid is bound to SQL server database using entity framework hence no MVVM pattern. The copy from datagrid seems to work with a few codes (seems...
6 Sep 2022 by mojtabahakimian
I have C# WPF project that is save data from DataGrid into a Table in SQL Server Database In Database I have two tables as Factor and Commodity that related to each other and -The ItemsSource of the DatGrid is filled from the Factor table -The...
3 Sep 2022 by mojtabahakimian
I am using C# WPF and currently, I am loading some data from the database in Datagrid. I loading more than 24,000 rows from a table in the database into DataGridComboBoxColumn, the problem is that when I open the Combobox it is very slow so it...
1 Sep 2022 by Member 15691986
I've wpf application, where I load large data (into Wpf DataGrid) and handle multiple events per 1-5 seconds.. I have a performance issue with datagrid - rendering takes too long and freezes my app until it's all rendered. What I have tried: ...
23 Aug 2022 by CIDEY
I would like to make it so that when you double-click on a cell, the program defines an instance of the class and changes its attribute in the database, after which a request is sent to the server every 5 seconds, and the selected object will go...
22 Aug 2022 by hardover
This question has not resulted in a workable solution. It is likely due to poor problem definition/communication on my part. I am closing it. I have made another example and question, a better attempt a problem definition/communication....
22 Aug 2022 by hardover
I can’t make binding work to a UserControl in DataGridTemplateColumn. The UserControl is TagSelect. It works with the first two independent uses in this example. I have confirmed that the DP SelectedTags is not binding when used in the DataGrid....
9 Aug 2022 by Graeme_Grant
1. This is trying to point to a Collection of type Tags on the DataContext of the MainWindow. You have set it to...
2 Aug 2022 by CIDEY
It is necessary to implement a table (DataGrid), which is initially empty. It has 2 fields: The current date and the item selected from the ComboBox. How to refer to ComboBox'u if it's impossible by x:Name'u? Here is an code: plusBtn.Click +=...
2 Aug 2022 by Gerry Schmitz
How to: Find ControlTemplate-Generated Elements - WPF .NET Framework | Microsoft Docs[^] https://stackoverflow.com/questions/8126700/how-do-i-access-an-element-of-a-control-template-from-within-code-behind[^]
27 Jul 2022 by Petr Barabáš
Hey, I'm trying to automatically add new records to DataGrid. Everything works, but the DataGrid is refreshing every time. I want to keep it unchanged, only if a new record comes in, I want to add it public class Example{ public static...
26 Jul 2022 by Petr Barabáš
I'm trying to dynamically add records to DataGrid (which I take from mails, running in the background). The problem is that when I use the method on the other thread to start the XAML window, it just prints some records not every one and not...
25 Jul 2022 by Reza jafery
Hi, I have a DataGrid that is related to the book specifications. Inventory is one of these specifications. To avoid user error, I automatically calculate the Inventory of that book based on its ISBN and save these changes in the Access database...
12 May 2022 by OriginalGriff
Don't work from a DataGridView directly - use it's data source instead, which is often a DataTable loaded from a DB or file. That way, you separate the presentation details from the data storage and get more reusable code. And you can then use...
12 May 2022 by User 15393223
I have already a working code in WinForm but I want to write back in WPF but I cannot do it because I am new in WPF. Can you guys try to convert it to WPF? if (myGrid.RowCount > 0) { string...
24 Mar 2022 by OriginalGriff
When you run any time-intensive operation on the default thread, the application can't do anything else (like update the display or respond to user inputs) until the long running method exits. So what you need to do is move it to a different...
24 Mar 2022 by Devendra Sarang
My application hangs when performing large number of update operations. I have one DataGridView. Now I want to update any cell value from any row as per requirement. So I am editing it, and on clicking on one single "Save" button, all the row...
23 Mar 2022 by CHill60
Databases are set based - so don't do this line by line. There are several similar questions here on CodeProject that offer more appropriate solutions e.g. C# how to save changes in datagridview to sql?[^] - and if you look to the right side of...
26 Jan 2022 by M Imran Ansari
You can achieve this using StackedHeaderRows. Check the following link and code repo: GitHub - SyncfusionExamples/how-to-create-wpf-datagrid-with-multiple-header-rows: How to create wpf datagrid with multiple header rows (stacked header rows)?[^]
9 Jan 2022 by Palash Sachan
How do i remove this blank space from gridview in asp.net? please see this IMAGE I want to remove this blank white space NOT hide this(as I know we can hide this border very easily) even after hiding the border the white unused space is there i want to remove that please see this IMAGE my...
9 Jan 2022 by Hasan Turer
Try this. Deleting or editing before binding to datatable is easier and more secure I think. public static void RemoveEmptyDataTable(DataTable dt) { for (int i = dt.Rows.Count - 1; i >= 0; i--) { ...
3 Jan 2022 by Peter Huber SG
A deep dive into how to easily display data exactly the way you want when DataGrid is not up to the task
4 Dec 2021 by Bill Joeden
Suppose, I have the following DataGrid: How do I add the following list of objects to the customershowgrid DataGrid to display all the customer instances' attributes like name, phoneno etc. What I have...
4 Dec 2021 by Gerry Schmitz
Based on your "field names" and your "property" reference (name {get;set;}) I would say you did not use the (private) "fields" as backing stores for the "properties", and you should be using "property names" in your initializer. i.e. new xxx() {...
3 Dec 2021 by #realJSOP
The bound collection property has to be public, or it won't bind. public class MainWindow: Window, INotifyPropertyChanged { // put your INotifyPropertyChanged implementation here // private...
27 Oct 2021 by iAnkitBhatt
Problem statement - WPF Datagrid is formatted with LoadingRow="DataGrid_OnLoadingRow" 1.Datagrid on full page (100 Rows) 2.Condition rows ID
27 Oct 2021 by Maciej Los
All you need to do is to loop through the collection of rows in datagridview and export them do Excel via using, for example: EPPlus library[^]. How to use it? See: Home · JanKallman/EPPlus Wiki · GitHub[^]
6 Oct 2021 by Member 11298827
I'm new to Xamarin Forms, most of my experience is with Windows Forms and C#. The project I'm trying make has a DataGrid using Xamarin.Forms.DataGrid, and a button to use for updating the data and refreshing the DataGrid. The project is based on...
6 Oct 2021 by Member 11298827
Since the time I posted this question I have found a suitable solution. I found a different example that used ListView instead of DataGrid. While I really needed DataGrid, I thought I might be able to use the same technique since the ListView...
6 Oct 2021 by Devendra Sarang
I have 1 grid view. On gridview cell click, it will show relavant data in another gridview. Now another gridview has DataGridViewComboBoxColumn Its data is loading but is is showing when i click on it. Bu default it is showing blank. Like...
6 Oct 2021 by mirajanata
This is binding problem, maybe this helps: cmbContactsName.DataSource = dt2.DefaultView; instead of cmbContactsName.DataSource = dt2;
6 Oct 2021 by CHill60
Try this order instead - it's the setting of DataSource that I've moved to after the ValueMember and DisplayMembercmbContactsName.ValueMember = "ContactsID"; cmbContactsName.DisplayMember = "Contact"; cmbContactsName.DataPropertyName =...