Questions tagged [datagridview]

DataGridView is a Windows Forms control used to display and edit tabular data.

DataGridView is a Windows Forms control found in the .NET Framework starting at version 2.0. It is used to display and edit tabular data from many different kinds of data sources. It provides a rich set of features such as sorting, filtering, grouping, and editing data.

Useful links

20349 questions
23
votes
6 answers

Best way to fill DataGridView with large amount of data

I have a windows form that has two DataGridViews (DGVs) that will hold 25,000+ records and 21 columns each. I have successfully loaded each with the data from the DB using a DataAdapter and then I tried simply filling the DGVs using for loops. …
Bkins
  • 407
  • 1
  • 3
  • 11
23
votes
8 answers

How to show only certain columns in a DataGridView with custom objects

I have a DataGridView and I need to add custom objects to it. Consider the following code: DataGridView grid = new DataGridView(); grid.DataSource = objects; With this code I get a DataGridView object with all properties as columns. In my case, I…
Cristhian Boujon
  • 4,060
  • 13
  • 51
  • 90
23
votes
11 answers

C# DataGridView sorting with Generic List as underlying source

I'm using a Windows Forms DataGridView to display a generic list of MyObject objects. First of all I wrap this collection into a BindingSource Collection, then: dataGridView.DataSource = myBindingSource; What I want to do is allow the user to sort…
theSpyCry
  • 12,073
  • 28
  • 96
  • 152
23
votes
7 answers

C# Iterate Over DataGridView & Change Row Color

I have a datagridview made up of multiple rows and columns. I want to iterate through each row and check the contents of a specific column. If that column contains the word "NO", I want to change the forecolor of the entire row to Red. Here is an…
Goober
  • 13,146
  • 50
  • 126
  • 195
22
votes
1 answer

Determine cell location in DataGridView

Given a specific row number and column index how can I calculate the cell location (IE: Location.Point) inside a DataGridView? The reason I need the location of the cell is so I can position a button inside the cell to allow for folder browsing (the…
Maxim Gershkovich
  • 45,951
  • 44
  • 147
  • 243
22
votes
8 answers

How to get DataGridView cell value in messagebox?

How can I get DataGridView cell value to be written in the MessageBox in C#?
Brezhnews
  • 365
  • 2
  • 6
  • 13
22
votes
3 answers

DataGridView: How to make some cells unselectable?

How can I make some cells in DataGridView unselectable? By 'unselectable' I mean: It cannot be selected in any way and trying to select it won't unselect any other cell. I don't mean ReadOnly. My cells already have this property as…
Miko Kronn
  • 2,434
  • 10
  • 33
  • 44
22
votes
5 answers

DataGridView bound to BindingList does not refresh when value changed

I have a DataGridView bound to a BindingList (C# Windows Forms). If I change one of the values in an item in the list it does not immediately show up in the grid. If I click on the changed cell, or minimize then maximize the window it updates…
C Walker
  • 793
  • 2
  • 9
  • 19
22
votes
3 answers

How to add a button to a column in the DataGridView

DataTable dt = new DataTable(); dt.Columns.Add(new DataColumn("Software Title", typeof(string))); dt.Columns.Add(new DataColumn("Version", typeof(string))); dt.Columns.Add(new DataColumn("Uninstall", typeof(System.Windows.Forms.Button))); DataRow…
software is fun
  • 7,286
  • 18
  • 71
  • 129
22
votes
10 answers

DataGridView changing cell background color

I have the following code : private void dgvStatus_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e) { foreach (DataGridViewRow row in dgvStatus.Rows) { row.Cells[color.Index].Style.BackColor =…
Rémi
  • 3,867
  • 5
  • 28
  • 44
21
votes
3 answers

WinForm binding radio button

I use VS2010 and then drag and drop Member datagridview to design view. After that I drag and drop name member textfield to design view and then try to edit and save. It's work properly. And then I drag and drop sex radio button to design view. But…
korrawit
  • 1,000
  • 2
  • 18
  • 30
21
votes
6 answers

How to sort DataGridView when bound to a binding source that is linked to an EF4 Entity

I have a DataGridView that is linked to a BindingSource. My BindingSource is linked to an IQueryable list of entities: public void BindTo(IQueryable elements) { BindingSource source = new BindingSource(); source.DataSource =…
Martin
  • 39,569
  • 20
  • 99
  • 130
21
votes
5 answers

C#: Custom sort of DataGridView

I need to sort a DataGridView with Natural Sorting (Like in Explorer) so that numbers and text (in the same column) are sorted naturally, and not alphabetically (so that "place 3" comes before "place 20", etc.). I have a DataGridView, where I have…
Svish
  • 152,914
  • 173
  • 462
  • 620
21
votes
2 answers

BindingSource - what are the advantages of using BindingSource

What gives me using something like this: DataGridView dgvDocuments = new DataGridView(); BindingSource bindingSource = new BindingSource(); DataTable dtDocuments; dtDocuments = MsSQL.GetDocuments(dtpOd.Value, dtpDo.Value); bindingSource.DataSource…
Adam Filipek
  • 213
  • 1
  • 2
  • 5
21
votes
4 answers

How to disable creation of new rows in a DataGridView?

This is about a .NET Windows Forms application written in C#. I have a DataGridView which is connected to a database. It displays the contents of a selected table. Now if there are 4 rows in that table, it will display 4 rows. After this I am able…
saeed
  • 673
  • 3
  • 12
  • 22