Click here to Skip to main content
15,886,795 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 Score

DataGrid 

11 Apr 2013 by xllance
An approach to bind datagrids through ITypedList interface.
20 Dec 2020 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)
24 Feb 2019 by chuck in st paul
This is a utility program for bulk/batch renaming of files that demonstrates using and creating events
24 Jan 2011 by Henry Minute
You'll laugh when I point out the problem.Here is the modified code (I have changed a couple of your variable names to make it clearer): int row1 = (this.agentsDataGridView.CurrentCell.RowIndex); int col1 = (this.agentsDataGridView.CurrentCell.ColumnIndex); ...
5 Nov 2011 by Frank Augustin
Describe validation when presenting data in WPF Toolkit’s DataGrid.
25 Jan 2012 by Sergey Alexandrovich Kryukov
Maybe you can find some, or someone helps you, but I hardly can imagine an author who would like to spend time on a whole book or a Web site devoted to just one class — System.Windows.Controls.DataGrid,...
25 Jan 2012 by Espen Harlinn
While SAKryukov has provided an excellent answer, I guess you would like some examples on how to use the WPF DataGrid too:WPF DataGrid Practical Examples[^]Introduction to the WPF DataGrid[^]MVVM and the WPF DataGrid[^]And here is Jaime Rodriguez article on how to style the WPF...
31 Aug 2011 by Peter_Smithson
Using the DataZGrid provided by .NET 4, this article shows how to copy and paste between cells.
29 Nov 2012 by RovenetBill
ASP.NET c# component for editing SQL tables with plug-in column format adapter architecture.
9 Aug 2011 by Prerak Patel
Hey, check this out, if it helpshttp://stackoverflow.com/questions/3701866/highlighting-columns-on-a-wpf-datagrid-as-mouse-moves[^]
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.
13 Jan 2011 by Simon_Whale
import the excel data and run an outer join queryAccess Outer join query[^]
25 Jan 2012 by Shahin Khorshidnia
Hello. Why don't you have 2 collections?I prefer to bind my grid to a collection, thereafter, if I modify my collection, the grid will be change automatically.After modifing the collection put this code:YourDataGrid.ItemsSource = YourCollection;then the grid will refresh.
25 Sep 2012 by OriginalGriff
The possibilities are pretty obvious:1) categoryMember is null, either because CategoryDataGrid.SelectedItem is null, or is not a CategoryTbl,or2) CategoryName is null.Put a breakpoint on the first line of the handler, and step through until you find out which. Then you can either fix...
12 Feb 2016 by lakhdarr
Different ways to export a grid contents to different file formats csv, excel, pdf using ASP MVC
20 Dec 2020 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)
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...
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 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...
24 Nov 2010 by Toniyo Jackson
As i understand ur question,Select count(*) from tablename where paidDate >= '01/11/2010' and paidDate
24 Nov 2010 by Sandeep Mewara
Well, first of all design the datavase tables such that you can capture all data.For now, assuming once a transporationID is related to a ClientID, whole month is used. It would give something like, transportation cost of that transportationID * 30 days!Thus, to be generic, you need to...
25 Dec 2010 by Pete O'Hanlon
In order to do this, you are going to have to override the datagrid template and draw this yourself. If you want to see how to do this, Dan Wahlin has an excellent example here[^].
6 Mar 2011 by steini1441
HiI have a winforms app I'm trying to port to WPF. In that I have a datagridview bound to a bindingsource and use BindingSource.Filter = string.Format("Column LIKE '%{0}%'", tb_Filter.Text);in a textchanged event method to let the user filter the datagrid in real time.I'd like to do...
14 Mar 2011 by Sandeep Mewara
:doh:I am sorry but there is no quick question here. This is your college assignment, you should put some effort.We expect you to put some time in trying the issue that you are facing and then some time in formulating the question while posting here. I see both missing. :doh:Here is...
2 Jun 2011 by Sanjay J Patolia
Hi,I think your code is correct it should work but why you are doing RegionDataSet.Tables.Add(new DataTable("dt")); DataSet RegionDataSet = new DataSet(); RegionDataSet.ReadXml(strPathtoRegion); dataGridView1.DataSource = RegionDataSet; dataGridView1.DataBind();This...
6 Aug 2011 by Mike Hankey
What DataGridView properties are you wanting to expose?You would expose them in the same way you did the EmployeeFirstNametxt.Text property,for example to expose the DataGridViews DataSource property;public object DataGridViewDataSource{ get { return dgv.DataSource; } set...
6 Sep 2011 by Abhinav S
You do not pass a DataGridView to a Dataset.You assign the source of the DataGridView to the DataSet.Read Creating Crystal Reports using C# with Datasets[^] if you want to set a DataSet as the source for a Crystal Report.
6 Sep 2011 by Wendelius
DataGridView is a class to visualize the data where as dataset contains 'only' data. If you already have a data datagridview, you propably have a dataset or datatable defined for the datagridview's datasource property. If that's true then you can take that dataset and pass it to crystal.
20 Nov 2011 by Mehdi Gholam
I have found a possible solution here : http://www.dotnetmonster.com/Uwe/Forum.aspx/winform-data-binding/1042/BindingSource-Filter-fails-when-datasource-derives[^]
28 Nov 2011 by Mark Salsbery
Quote:a way to bind a DatagridComboBoxColumn's ItemsSource to the Datagrid to which it belongsDoes a FindAncestor binding work?ItemsSource="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type DataGrid}}, Path=MyCollectionProperty}"
20 Jan 2012 by Member 8192334
So, one more update to this puppy just to let folks know about new information that I found. In my LoadingRow event handler previously, I was setting the variable like this:DataRowView item = e.Row.Item as DataRowView;and then checking it's value, only to find that the value of item was...
20 Jan 2012 by Shahin Khorshidnia
HelloStyle style = new System.Windows.Style();style.TargetType = typeof(TextBlock);Setter setter = new Setter();setter.Property = DependencyProperty.Register("TextAlignment", typeof(TextAlignment), typeof(Setter));setter.Value =...
7 Jul 2012 by M.H. Shojaei
I resolved it: private void textBox1_TextChanged(object sender, TextChangedEventArgs e) { try { SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=E:\Personel.mdf;Integrated Security=True;User...
28 Nov 2012 by gregsagan
I have an issue in regards to my application, and not selecting an item for it to get updated using EF.I'm creating an application for a user to enter in their organisation details. Seems simple enough. After data has been entered using a tab control, I have a view that contains a series of...
1 Dec 2012 by Member 8022218
hi The idea is to make DataGrid contains a field of type combobox it have another data source to choose from those and save data in the DataGrid , this is possible and without any problems..But when make Parameters to filter data in the combobox and when i try add records have different...
10 Dec 2012 by Jason Gleim
If you have added the converter and have not built the project, you will get that error. Any new classes you add to the project must be built before they will be picked up by the xaml interpreter.Secondly, make sure you don't have a namespace problem. For example, if you created a behaviors...
29 Dec 2012 by Karthik. A
That's because, you are not passing any data to your delete method that could enable it to redirect to the appropriate page. Following sample gives you an idea...Delete methodpublic ActionResult Delete(int itemId, int pageNo){ // delete the item using itemId // redirect to...
28 Mar 2013 by Richard C Bishop
As ThePhantomUpvoter so eloquently put it, you must write an Update statement in order to update a database. Ther are countless examples of them online.
24 Apr 2013 by GRF75
From different sources from the web, this finally worked:In XAML: In...
2 Jun 2013 by Sergey Alexandrovich Kryukov
Please see this discussion, answer #1: http://stackoverflow.com/questions/14847463/want-to-change-the-cell-background-color-in-wpf-datagrid[^].—SA
16 Sep 2013 by Maciej Los
Test it:DECLARE @lessons TABLE(LessonID INT IDENTITY(1,1), LessonName VARCHAR(30))INSERT INTO @lessons (LessonName)SELECT 'lesson A'UNION ALL SELECT 'lesson B'UNION ALL SELECT 'lesson C'UNION ALL SELECT 'lesson D'--UNION ALL SELECT 'lesson E'DECLARE @subject_lesson TABLE...
11 Oct 2013 by ASP.NET Community
The GridView control was introduced with ASP.NET 2.0 and Visual Studio 2005 as a replacement for the DataGrid control.  While it has many
17 Jan 2014 by Rahul VB
Hello Brother,Quote:The User should click on the Cell and edit the Cell by using his keyboard.Is a DataGrid the right thing for doing this? And How can I realize this? You can do this using TablelayoutPanelControl. I feel it is much more flexible(Please correct me if i am wrong). In a...
21 Jan 2014 by Sergey Alexandrovich Kryukov
Look at the XAML sample in the original MDSN documentation on System.Windows.Controls.GridView:http://msdn.microsoft.com/en-us/library/system.windows.controls.gridview%28v=vs.110%29.aspx[^].You need to use the XML element GridViewColumn with the attribute DisplayMemberBinding (again, see...
7 Feb 2014 by Matt T Heffron
I ended up doing this using a value converter for getting the tool tip:using System;using System.Data;using System.Globalization;using System.Windows.Controls;using System.Windows.Data;namespace PreQuant{ public class CellToolTipConverter : IMultiValueConverter { ...
6 May 2015 by CHill60
Have a look at datagridview.firstdisplayedscrollingrowindex[^]E.g.private void dataGridView1_SelectionChanged(object sender, EventArgs e){ if (dataGridView1.SelectedRows.Count == 0) return; dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.SelectedRows[0].Index;}The...
10 Nov 2016 by OriginalGriff
Why would you assume that i is valid for both dataGridView_auswahlen (row source) and table (row destination)?Since you are only transferring selected rows, unless your selection always starts with the first row and has no gaps, you will always get an exception.Instead of using an index,...
2 Jan 2017 by K-SIS
There is logical error.1. You are Filling in a loop so after every fill it will wipe previous filled data. (Data is replaced not appended.)2. connection is closed in loop so after first iteration the table object will be null.
3 Nov 2017 by Karthik_Mahalingam
try protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Select") // name of the command { var index = Convert.ToInt32(e.CommandArgument); var row = GridView1.Rows[index]; ...
9 May 2018 by Maciej Los
Maciej Los: Does your DataGridView is bind with datasource? If yes, what kind of datasource: BindingSource, DataTable, DataSet? Primo Chalice: It is DataSet In this case, the simplest way is to use: DataSet.WriteXml Method (System.Data)[^] and DataSet.ReadXml Method (System.Data)[^]
8 May 2019 by OriginalGriff
Not like that! Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Always use Parameterized queries instead. When you concatenate strings, you cause problems because SQL receives...
26 Apr 2020 by User 11060979
Like Maciej mentioned in the comment to the question you need to replace linenbreaks (linefeeds resp carriage linefeeds) with But it is not only a simple you have to add. To inform Excel to keep it in the same cell you need to replace...
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...
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...
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...
7 Nov 2010 by Pete O'Hanlon
You need to reference the XML in the resources, you can do this typically by : Then, hook up in your datagrid using ItemsSource="{Binding Source={StaticResource MyXML}}"
24 Dec 2010 by JF2015
Hi,have a look here:http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.datasource.aspx[^]and at the answer to this very similar question:DataGridView - changing DataSource at runtime[^]
29 Dec 2010 by Not Active
You don't delete data from the grid, you delete from the datasource bound to it.
22 Jan 2011 by Henry Minute
If your ComboBox is part of a ComboBoxColumn then Manfred's solution might not work.Take a look at this[^] thread on MSDN.Social (Scroll down until you see the first message from 'mcassoc') and in that message take note of the event handler for the EditingControlShowing event. Using that...
24 Jan 2011 by fjdiewornncalwe
You could always write a small converter utility that takes in a datagrid object and a requested header text returning the appropriate column index.private int GetColumnIndexByHeaderText( DataGrid dgObj, string headerText ){ // Loop through the columns and when you find the appropriate...
23 Jan 2011 by skatebkp
Hi,I am looking for a way to retain the cell selection on the DataGridView after I refresh the data set.This is the code I am playing with is: int cell1 = (this.agentsDataGridView.CurrentCell.RowIndex); int cell2 =...
7 Feb 2011 by Sandeep Mewara
Did you try using FindControl at cell level instead of indexing the control?
10 Feb 2011 by Nish Nishant
The Winforms DataGridView can be customized to show checkboxes, dropdowns etc., but your requirement seems to include custom layout changes too which may be too much with the DataGridView. If you don't want to fully move to WPF, you might at least want to just write this one control in WPF and...
6 Mar 2011 by Henry Minute
I don't know how helpful this is going to be to you, since you seem to already have the basics, but I found this article[^] yesterday.
18 Mar 2011 by walterhevedeich
You can get the selected cells values using the DataGrid.SelectedCells property and GetCellContent method of the DataGridColumn. For example:for (int i = 0; i
26 Mar 2011 by Henry Minute
The DataGridViewButtonColumn page on MSDN[^] shows how to add columns at runtime.You might also find this page[^] useful.
2 May 2011 by ankitjoshi24
HiI was wondering if it is possible to mask a column data to show it as a password character such ask "*"I want to display the username and password table using datagrid controlBut the datagrid control shows the password directly instead of masking it. So I want to mask the password...
3 May 2011 by JOAT-MON
One way you could accomplish this is to use the Paint() event to check the rows and if there are none, then write your message:private void dataGridView1_Paint ( object sender, PaintEventArgs e ){ DataGridView sndr = ( DataGridView )sender; if ( sndr.Rows.Count == 0 ) //
21 May 2011 by Sandeep Mewara
Instead of:DG1.DataSource = Dstry:DG1.DataSource = Ds.Tables(0)
24 May 2011 by suren.info
Before you bind your long data to the grid , convert the long to string.This can be done using inline methods when you are binding that particular column value in item template. or Convertion can be done in designer page as well.
30 May 2011 by Yıldız Murat
Hello Johnson,you can use this PL/SQL function to convert LONG field to VARCHAR2. create or replace function LONG_TO_CHAR(in_table_name varchar,in_column varchar2, in_id varchar)return varchar2 asmy_text varchar2(32767);my_sql varchar2(2000);begin sql_cur := 'select...
8 Dec 2020 by s1a2b3
Hello ,I am New to Vb.Net 2008 with Access 03Sample Code : This Fill All Agents in Desc Order by Selected Country in DropDownDim Da As New SDS.OleDbDataAdapter("select AgentId,count(TripId) AS Trips from Trip where country='" & CmbCountry.Text & "' group by AgentId order by...
7 Jun 2011 by thatraja
Try thisC# DataGridView Paging[^]
21 Jun 2011 by MGScott
I have a Page containing a DataGrid. I need to populate this from 2 separate sources. The 1st three columns of data I read from a text file (both the column headers, and the subsequent rows of data).After that there is anywhere from 1 to 100 columns I need to add that will just contain...
21 Jun 2011 by derinpdavis
you are adding (3 + data.SelectedAssays.Count) number of columns but supplying only three data fields {strParts[0], strParts[1], strParts[2]};so you have to specify for what all columns the data goes to col.DisplayIndex = nIdx;col.Header = strColHeaders[ nIdx...
21 Jun 2011 by 2irfanshaikh
Just put e.Handled = true; in both the events CurrentCellDirtyStateChanged CellValueChanged I think it will help you.
23 Jun 2011 by Manish V Mahajan
Was to find a solution posted on MSDN ( href="http://social.msdn.microsoft.com/Forums/en/wpf/thread/7fd1df22-03b9-408b-80a4-e0a642a3a857">).Basically I did the following:1. Add a MouseDoubleClick in my main DataGrid (this works even though you have DataGridTextColumn or...
24 Jun 2011 by Archna G
Is there any simple way to handle the row double click event in a silverlight datagrid using the MVVM approach.Thanks in advance.
27 Jun 2011 by WPFNub
Since I could not get any answers from this forum, I posted it on MSDN and I have posted the final approach here: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/cf3fbd6f-1d8a-47b5-b87b-5c7d8bd1c963
2 Jul 2011 by Rajesh Lagaria
check datagridview properties "AllowUserToAddRows" if it set "True" then set "False"hope this help
25 Jul 2011 by Dave Kreskowiak
The easy way to do it is to just set the DataSource of the DGV again. You might have to set it to Nothing first.But, of course, this depends on what you're binding the DGV to. Your code for this looks like .....??
15 Apr 2013 by mrpotatohead
i was able to solve it by myself, oh well after 4 days. I know this will be a good use for those doing similar to mine...fellows here's the sample code you may use :Dusing System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using...
7 Sep 2011 by Prerak Patel
Check events RowsAdded, RowsRemoved, CancelRowEdit, RowStateChanged.http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview_events.aspx[^]
7 Sep 2011 by mnd017
Hi,My problem is a little complex, but I have no idea how to solve it, so i try to ask you about this.In WPF, my datagird column header is sortable. So, when i click once, the arrow appears and datagrid is sorted desc, then asc etc.. I need to have a sorted (with arrow visible) datagrid...
8 Sep 2011 by Wayne Gaylard
When it comes to sorting your DataGrid, the best thing is to use a CollectionView with a SortDescription. In XAML it would look something like this:- ...
13 Sep 2011 by Wayne Gaylard
To start with, binding to datasets and datatables is not the best solution in WPF applications, you really should use ADO.Net and a DataReader to convert your database info into CLR objects, in this case an ObservableCollection. You can then bind you datagrid to the collection, rather...
13 Sep 2011 by Simon Bang Terkildsen
Make MainViewModel.Empdata public, and do not initialize it twice it's not an error just redundant.My article might also be able to help you now and in the futureDebugging WPF data bindings[^]It might be tricky to understnd if you're really that new to data binding in WPF, but you're...
13 Sep 2011 by somasekhar_37
am completely new to MVVM. I was trying to bind the data from sqlserver to the Datagrid in WPF and perform Edit, update and delete operations on it. now, am unable to bind the data from sqlserver to datagrid atleast using observable collection in MVVM.... someone please help me out to resolve it...
21 Sep 2011 by Herman<T>.Instance
Look for the UnPivot command: http://msdn.microsoft.com/en-us/library/ms177410.aspx[^]
23 Sep 2011 by AnilBaviskar
Hello All,I am facing difficulty in below situation:I have WPF datagrid with few columns. I want to show/hide certaincolumns based on combobox selection change.I tried using StaticResources, ObjectDataSource etc options but no use.What collection I should use & how the binding...
14 Oct 2011 by Sagar Rawal
http://example...
14 Oct 2011 by Sagar Rawal
datagrid is the Object of DataGrid.datagrid.setStyle("color","#000000");datagrid.setStyle("fontFamily","Verdana");datagrid.setStyle("fontSize","11");visit the following Linkhttp://examples.adobe.com/flex2/consulting/styleexplorer/Flex2StyleExplorer.html
31 Oct 2011 by Espen Harlinn
Have a look at:WPF DataGrid Practical Examples[^]Best regardsEspen Harlinn
20 Nov 2011 by Sander Rossel
Hi folks,I have been working with Entity Framework and binding for quite a while now. When suddenly the following struck me: A BindingSource has Sort and Filter Properties.These are only supported when the bound Object Implements IBindingList or IBindingListView. A standard List does not...
28 Nov 2011 by Shmuel Zang
You can bind it using RelativeSource like Mark wrote. But, why do you use the AncestorLevel property? Try to omit it.Another way is to bind it using ElementName. Just set a name to the DataGrid and, bind to it using this name, like the following: ...
21 Dec 2011 by sadel
search button for vb 2010 ultimate in access 2007 database and filtering on a datagridHi all!I create a wpf file and I am trying to make a search button which filters a datagrid. First of all, I have a tab and on this tab a have a datagrid (dgr1). When I load this tab, I fill in a...
1 Jan 2012 by Rajeev Jayaram
See this similar answer[^]
18 Jan 2012 by MohammadIqbal
private void button2_Click(object sender, RoutedEventArgs e) { connectionstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:/Project/Book.accdb"; connection = new OleDbConnection(connectionstring); sql = "Select*from...
18 Jan 2012 by Shahin Khorshidnia
after stackPanel1.Children.Add(dg2);use dg2.ItemsSource = Your SourceI think it can help.