Click here to Skip to main content
15,892,927 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 

18 Oct 2016 by #realJSOP
private static void EnsureVisibleRow(DataGridView view, int rowToShow){ if (rowToShow >= 0 && rowToShow
1 Nov 2016 by #realJSOP
Define your Dictionary as a public property in your C# code, and do this in the XAML. ...
21 Nov 2016 by #realJSOP
0) You need a public property to bind to. public Userss Users { get; set; }And you can set the DataContext in the constructor:this.DataContext=this;1) Why are you setting the ItemsSource in both the XAML and the code-behind?2) Compartmentalize your code. Put the database...
17 Jun 2019 by #realJSOP
It's probably taking a long time because you're doing a join inside your insert statement. Refactor your insert statement.
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...
5 Jan 2015 by .Net Jim
Appeal to Silverlight senior coders out there. I am a .Net developer with a few years of ASP.Net and a year or so Web Forms, and 6 months of Silverlight and WPF.I have a datagrid on a tab in silverlight that must total itself based on check columns selected. Columns are annual budget...
26 Nov 2014 by 123456789shaik
hii need to search data in datagrid view with different fields i am geting error for that syntax error at keyword WHEREbut it is executing for single field but i need two more field to search with one textboxplease help me...my code is hereprivate void button1_Click(object...
21 Jun 2011 by 2irfanshaikh
I think this will help youhttp://stackoverflow.com/questions/1296532/making-a-datagrid-column-header-sortable-in-wpf-using-c[^]Or else try to put it into the SortMemberPath header template
21 Jun 2011 by 2irfanshaikh
Just put e.Handled = true; in both the events CurrentCellDirtyStateChanged CellValueChanged I think it will help you.
22 Jun 2011 by 2irfanshaikh
i think we can use DataGrid.SelectedCells.Also check this link[^].
12 Feb 2012 by 2irfanshaikh
I think this link will help you.http://bytes.com/topic/c-sharp/answers/900106-how-add-datagridcomboboxcolumn-datagrid-wpf[^]
15 Nov 2010 by 35aim
Hi Mukesh I need Project Files for for CustomControl.Collapsible DataGrid.......my Id is vidhyut_mca@gmail.com.thanksvidhyut
15 Nov 2010 by 35aim
thanks a lot Mukesh ....i have used your DLL as part of my Application so as a control i need that projects...thanks again.vidhyut
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...
7 Feb 2015 by [raizhin]
hi everyone, please help me with my program. i really need help :(im using visual studio 2010 database: ms access 2013 tables: student,subject,quiz,exams,projectsprogram : 1.) the user will save his subjects to the database 2.) The user will add stdents into the...
15 Mar 2011 by _Ashish
try this on button click Response.Clear() Response.AddHeader("content-disposition", "attachment;filename=FileName.xls") Response.Charset = "" Response.Cache.SetCacheability(HttpCacheability.NoCache) Response.ContentType = "application/vnd.xls" ...
21 Mar 2013 by _Maxxx_
There's a nice article about that here[^]
12 Feb 2018 by aaronzeng
protected void ImportCSV(object sender, EventArgs e) { //Upload and save the file string csvPath = Server.MapPath("~/Files/") + Path.GetFileName(FileUpload1.PostedFile.FileName); FileUpload1.SaveAs(csvPath); //Create a DataTable. DataTable dt = new DataTable(); ...
12 Feb 2018 by aaronzeng
have the option to save the contents of the listview that was saved into text file. now i would like to load the text file into datagridview in vb.net but i have no idea how to do it as this is my first time in doing it and i had googled around but couldn't find the information i needed. can...
5 Jan 2012 by Abbath1349
I posted two DataGrid on a form, but in the 2nd DataGrid binding does not work. The properties ItemsSource they show the same values. If one change in the second changes automatically. How do I make it work properly?
6 Jan 2012 by Abbath1349
relevant code: private void themeSelector2_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { if (myDataSet.Tables["Asks"]!=null) myDataSet.Tables["Asks"].Clear(); ...
4 Aug 2016 by abdujalilc
This c# code works fine in wpf framework.Now I need this code in asp.net.I am using GridView instead of DataGrid.What changes do I have to do?Here is my c# code:DataRowView SelectedRowValue = (DataRowView)dataGrid1.SelectedValue;byte[] ImageBytes =...
24 Sep 2012 by Abhijit Parab
Call Grid.DataBind() method after Grid.DataSource = DT;I hope this is the thing which is missing in your code
28 Nov 2010 by Abhinav S
Maybe this[^] can help.
1 Apr 2011 by Abhinav S
This article[^] could give you some code that you can use.
14 Apr 2011 by Abhinav S
You might want to visit the RadGrid forums. This code looks fine to me.
17 Apr 2011 by Abhinav S
If you have the source code for your user control, you might want to attach it to your project and debug it. Specifically, you need to look at the bits that are fetching date into your control - looks like something might be wrong there. You should also take a look at your connection string to...
1 May 2011 by Abhinav S
This [^]could give you some ideas.
12 May 2011 by Abhinav S
This[^] could help you.
15 May 2011 by Abhinav S
More links - Export DataGrid to Excel[^]Exporting DataGrid to Excel, Word and Text Files[^]Excel export from DatagridView[^]Generalized DataGridView Export to Excel with Theme and Formatting[^]
8 Jun 2011 by Abhinav S
I searched on the internet and honestly, there are a large number of sites that have articles on paging.Searching on CP too will give you a number of resuts - starting with GridView Custom Paging[^].
1 Sep 2011 by Abhinav S
For the second item, you can handle the Delete key at row header lever and cell level.SO if a user hits Delete while he is focusing on a header, remove the row.If he is currently focusing on a cell, remove the cell contents.
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.
9 Dec 2011 by Abhinav S
You will need a to update the underlying datasource everytime the table changes.Have a look at event based processing[^].
15 Dec 2011 by Abhinav S
Simple - get the count of the collection that you bind to the DataGridView.
25 Jan 2012 by Abhinav S
This[^] might help you out.
30 Jan 2013 by Abhinav S
This could be possible to do in a number of interesting ways.The simplest would be to handle the the keydown event on the grid (capture Ctrl + V).Here are some articles that might help you...
1 Apr 2013 by Abhinav S
Loop through the rows of the datagrid, and basaed on your conditions change the color.For e.g.for(int i = 0; i
19 Oct 2013 by Abhinav S
This exception is thrown when you try and change the value of a readonly[^] column.Here[^] is a guide that will make you troubleshoot this problem.
2 Feb 2014 by Abhinav S
You have to give the approrpate flags to emit fields - e.g. http://msdn.microsoft.com/en-us/library/system.reflection.fieldattributes%28v=vs.110%29.aspx[^].
19 Mar 2014 by Abhinav S
TryChange Background Color of DataGrid Row on Some Condition [^]Change individual DataGridView row colors based on column value[^]http://asimsajjad.blogspot.com/2010/10/changing-background-color-of-datagrid.html[^]
4 Aug 2014 by Abhinav S
Try these links -Change row style of WPF grid[^]WPF DataGrid Custommization using Style and Template[^]WPF DataGrid – Styling rows and columns based on Header conditions and other properties[^]
4 Aug 2014 by Abhinav S
Template the cells with a TextBlock which has text-wrapping enabled.Here[^] is an example.
16 Aug 2014 by Abhinav S
Try these links on databinding -WPF DataGrid Practical Examples[^]Guide to WPF DataGrid formatting using bindings[^]Windows Presentation Foundation Data Binding: Part 1[^]
21 Feb 2015 by Abhinav S
This is for cells - https://sweav3r.wordpress.com/2007/09/15/blinking-wpf-datagrid-cells/[^] - the same logic can be applied to rows.
7 Jan 2016 by Abhinav S
This answer[^] should help you.
5 Feb 2014 by abhinav1223
I have a Listbox in which I have added two controls i.e a Checkbox and a Datagrid side by side as a Listboxitem. I have done it in a following manner:In Code behind: listBox1.items.Add(dt)here dt is the table name.In Xaml: ...
27 Mar 2013 by Abhinav_Sharma
I am currently working on a custom canvas and in that i have to add a table,So i thought dataGrid would be fine. SO i Want to create a "Table" from "Datagrid" by which user can add a table to the canvas at runtime.Till now, I have tried to Populate DataGrid With a list and succeded.How...
3 Apr 2013 by Abhinav_Sharma
Actually I want to populate dataGrid with Xml data present in xmlfile and want to add/remove/update the data in the Datagrid. I tried using XmlDataprovider which works fine in populating the dataGrid but I can't manipulate(add/remove/update)the data. Hence ObservableCollection was a...
4 Jul 2012 by Abolfazl Beigi
I hope this will help you.]]>
2 Jul 2011 by acheoacheo
Hi,I'm using paths to retrieve images that will be displayed in a DataGridView. If I load one image, it's fine, if I try to load 2 or more images, only the last one gets displayed in the DataGridView. Any idea why this is happening?thanksDataGridViewImageColumn iconColumn = new...
16 Sep 2012 by Adam David Hill
Try this:gridView.ItemsSource = ds.Tables["Table"].AsEnumerable();
18 Dec 2020 by Adilcan Topuz
The CellEndEdit event is running when I edit the datagridview cells. but when I print the data from the database to the DataGridView cell, CellEndEdit does not work. dataGridView1.Rows[0].Cells[0].Value = "test"; How can I run CellEndEdit? THANKS... Codes: private void btnKaydet_Click(object...
28 May 2012 by Adwaitam
HiI am having a DataGrid and need to change the color of the row in datagrid on clicking the Delete LinkButton in Datagrid.Please help.ThanKs.
21 Jun 2011 by afva
Hello , In my datagrid my textColumn looks like:Collapse IsReadOnly="True" Width="300" Binding="{Binding Path=CT_APPR.NAME}" SortMemberPath="{Binding Path=CT_APPR.NAME}" >My datagrid looks fine, so the binding is correct.But when I click on the...
18 Jun 2014 by agent_kruger
Example i have 40 rows and at a time only 20 rows can be displayed and other rows go in the scrollbar. How to set the last row of the datagridview as frozen? If i am setting the last row as frozen the scrollbar disappears. How to solve this?Thanks in advance
13 Feb 2015 by agent_kruger
How can i create a property named IsCheck (value true/false) in DataGridViewTextBoxColumn?i searched the internet but cannot find a solution to create property. Please help me with a code snippet or so.
1 Oct 2013 by Ahmad_kelany
Hello every one,trying to use a datagrid as data entry toolthe datagrid has 4 columns (code,name,price, quantity)i try to add an empty row through code like this :datagrid1.items.add(new datagridrow)but i get null reference exception...i really don't know why !then tried...
2 Oct 2013 by Ahmad_kelany
I have found the solution here :http://social.msdn.microsoft.com/Forums/vstudio/en-US/6d4cd15c-2bce-41ad-b812-5d71ebf05d5a/using-unbound-datagrid-as-data-entry-tool-wpfvbdatagrid[^]thanks every one
1 Jan 2018 by Ahmed Dabas
I have a DataGrid with two columns , one theme is checkbox column and the other is text column . I want to iterate through DataGrid Rows and check if CheckBox Cell was Checked , then add this row to list of employee it's in winforms all to do that: foreach(var r in DataGridRows) { ...
29 Jan 2018 by ahmed_sa
Problem Export datagridview to excel data exported without Header text of column . Detais when export datagridview to excel it export success but all data exported without header so How to solve this problem . private void releaseObject(object obj) { try { ...
3 Mar 2018 by ahmed_sa
I need write code for go next line when click enter on column Address I have a data gridview with 4 columns: ID,Name,Address,Amount I need when click enter key on any cell on column Address go to next line after press enter key . I using this datagridview to get data from database based...
11 Mar 2018 by ahmed_sa
Actually I need to print records have checkbox checked = true inside datagridview And if no any record checkbox checked meaning = false checked print all I need to do that under button print . No need to go inside code details I need only to implement only pseudo code below : pseudo code ...
9 Sep 2018 by ahmed_sa
Problem Barcode scanner return only first digit only why and How to Return Full Number as 6221133347389 6221133347389 return 6 4716201020476 return 4 screen shoot debug File sharing and storage made simple[
11 Sep 2021 by ahmed_sa
I work on c# windows desktop application on POS Form for pharmacy I need to read barcode to datagridview for every item AND when read another item again go to next line for every reading barcode so are there are any sample for pos form...
27 Feb 2013 by ajit ganesh
I have a table called A with 15 rows. I have used paging concept to display only 5 rows at initial load. Once the user clicks on next it will display me another 5 rows. Now Im gonna select any one or two rows and from table 'A' to table 'B'. Now I need to implement the same paging concept in...
27 Feb 2013 by ajit ganesh
Hi Jagan, Actually, I couldn't find any solution to restrict the rows to 5 i can only do like statements below.. but i can restrict for 5 but cant accomplish paging concept if(selectedFieldsTable.Rows.Count = 0; i--) ...
19 Mar 2013 by Akbar Ali Hussain
You can use "Like" and "%" in filter criteria as given below.BindingSource b = (BindingSource)dataGridView1.DataSource;b.Filter = "FullName like '%xyz%'";
10 Jun 2015 by Akbar Giffary
here my code :'for clear the date value Sub clear() dtpDOJ.Text = " "End sub'for return value to datetime picker when datagridview is clicked Private Sub dgvdatakaryawan_CellContentClick(ByVal sender As System.Object, ByVal e As...
10 Sep 2017 by Akbar Giffary
hi, i want to test/check when cells in data gridview is empty and when clicked it shows label like "there's a empty data in cell", thanks before If dgvdatakaryawan.Item(e.ColumnIndex, e.RowIndex).Value.ToString.Length = Nothing Then lblKET.Visible = True Else ...
18 Jun 2015 by Akbar Giffary
hi all, i have an annoying problem here..i want to delete selecting rows on my datagridview with connect to excel, but it show message like this "deleting data in a linked table is not supported by this ISAM", any sugestion, help me pleasehere my code :'for connectDim connstring =...
8 Feb 2011 by Albin Abel
It is not clear why can't the record id also append in the query string as each record display a hyperlink.It may not be safe to pass the user id in the url string. Refer this article for further information how to securely pass the query string parameters.Preventive Method for URL...
13 Dec 2012 by AlexandreN
I am trying to copy to clipboard my custom text data, after Ctrl+CDiverse attempts to use overrideOnCopyingRowClipboardContent(DataGridRowClipboardEventArgs args) or CopingRowClipboardContent event, don't help. Either clipboard gets empty or standard row text, but not what I would like to...
14 Dec 2012 by AlexandreN
Solution was foundYou need to set the ClipboardRowContent property of DataGridRowClipboardEventArgsstatic void dataGrid_CopyingRowClipboardContent(object sender, DataGridRowClipboardEventArgs e){ e.ClipboardRowContent.Clear(); e.ClipboardRowContent.Add(new...
7 Jul 2011 by Alimjan Yasin
I used DataGrid Control in my App. since I am new at WPF, there is always somestuff I don't understand. I want to each cell in DataGrid show Multi line text when dispalying Text is so much. I tried to find out solution and Tried some codes , but did not make it out. I find a way for make...
19 Jul 2011 by Alimjan Yasin
I am using wpf DataGrid with customedata source . the data source like blow:public class SentencesField { public int No{get;set;} public string TargetSen { get; set; } public string SourceSen { get; set; } public static List...
18 Nov 2012 by aliprogrammer
I make new column programmatically in c# windows application.for (int i = 0; i
1 Mar 2013 by aliwpf
Hi.You must define element style like this : ...
26 Apr 2015 by aliwpf
hi. i suggest use ValueConverter in wpf.
7 Sep 2011 by All Time Programming
Hi, I have a WPFToolkit's DataGrid added to my window. I am not able to figure out how to set Style to the Column Header and Rows ? Rows are added dynamically. SelectionMode="Extended" SelectionUnit="FullRow" CanUserReorderColumns="False" ...
29 Jan 2013 by ALOK CHANDAN
How to use Date Format in Datagridview in C#.Net(Window Form)
23 Mar 2017 by amagitech
I have a query which contains a true false value.If the value is true that means in call, else means outgoing call.I have tried something but there is an error like below. What is the wrongSeverity Code Description Project File Line Suppression StateError Cannot find the Trigger target...
23 Mar 2017 by amagitech
I have solved my question.firstly i give binding property for DataGridCheckBoxColumn later i used datatrigger for Datagridtemplatecolumn ...
19 Mar 2016 by amar nath chatterjee
Here is a template or pattern for using datagrid in building monitoring UI for simulations and tabulated data presentations.
18 May 2012 by amer-z
Good day I have one table in sql database one field is [date] it's type is date, for example (id,[date],[event])using C# windows form I need to add dateTimePicker and DataGrid datagrid is filling by db tableI need way to filter data in grid by introduction special date by...
25 Mar 2014 by amhy
I just combine from Jayasakthi & Solution from Rossel, and use in my code, it's work well in my vb.net code. thanks guys. bellow is the whole code.Private Sub dgvItemService_EditingControlShowing(sender As Object, e As DataGridViewEditingControlShowingEventArgs) Handles...
20 May 2011 by Amir Mahfoozi
Improve Delphi's TDBGrid by adding some new features to it
2 May 2011 by Amit Kumar Tiwari
Its been a long time since I worked on VB6 but I dont think that will be possible as VB6 doesnot allow datagrid customization.What you can do is, hide the password column and show a fake password column with hard code "****".When user edits the field, store the value enter in database and...
2 Jun 2011 by Amit Kumar Tiwari
Please have a look at article @ http://www.redmondpie.com/dynamic-controls-creation-in-a-c-wpf-application-part-2/[^]Hope that helps you, good luck.
31 May 2011 by amit28august
put ur code inside if condition If e.Item.DataItem ThenDim DRV As DataRowView = CType(e.Item.DataItem, DataRowView) Try If DRV.Row.Table.Columns.Contains("MyCustomColumn") Then Response.Write("data in column value") Else ...
12 Dec 2012 by AmitGajjar
Hi,Please check http://wpftutorial.net/DataGrid.html[^]This site is best for WPF beginner Best luck
9 Mar 2011 by amitkarnik2211
This might be usefulhttp://www.akadia.com/services/dotnet_arraylist_datagrid.html[^]
18 May 2012 by AmitKumar89
Hi,Try this links:http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/81ca9270-c9b9-492f-9313-f2d634583ee9[^]Filter datagridview using datetimepicker?[^]This may help you.All the best.-AK
5 Dec 2012 by amrita_thakur
Hi...I have a WPF Datagrid which I've grouped by a column ProductName. I want to perform sorting on UploadDate which is a datefield. The issue here is on clicking on sort I want the data to be sorted on UploadDate within the groups, by the datagrid sorts the data based on the ProductName, on...
2 Jul 2015 by an0ther1
Based on what is listed above, you need to create an event handler for the OnSelectedIndexChanged event - see below; OnSelectedIndexChanged="gListaDistributori_SelectedIndexChanged"> In your code behind you can then access the cell value as follows;Dim strMyValue as StringstrMyValue...
6 Feb 2015 by anand vemuri
for (int i = 0; i
24 Aug 2021 by Andre Dieme
Hello, I am trying to copy a Datagrid to Clipboard and paste it into word or excel. The DataGridTextColumns are working well. But I need to copy an Image Column.
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 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...