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
91
votes
8 answers

How to bind a List to a DataGridView control?

I have a simple List and I'd like it to be displayed in a DataGridView column. If the list would contain more complex objects, simply would establish the list as the value of its DataSource property. But when doing…
agnieszka
  • 14,897
  • 30
  • 95
  • 113
85
votes
7 answers

How can I right-align text in a DataGridView column?

How can I right-align text in a DataGridView column? I am writing a .NET WinForms application.
Jayantha Lal Sirisena
  • 21,216
  • 11
  • 71
  • 92
85
votes
9 answers

Horrible redraw performance of the DataGridView on one of my two screens

I've actually solved this, but I'm posting it for posterity. I ran into a very odd issue with the DataGridView on my dual-monitor system. The issue manifests itself as an EXTREMELY slow repaint of the control (like 30 seconds for a full repaint),…
Corey Ross
  • 1,995
  • 1
  • 15
  • 16
81
votes
19 answers

How to enable DataGridView sorting when user clicks on the column header?

I have a datagridview on my form and I populate it with this: dataGridView1.DataSource = students.Select(s => new { ID = s.StudentId, RUDE = s.RUDE, Nombre = s.Name, Apellidos = s.LastNameFather + " " + s.LastNameMother, Nacido = s.DateOfBirth }) …
delete
76
votes
9 answers

How to disable sort in DataGridView?

How can I disable sort in DataGridView? I need to disable the header DataGridView sorting.
Gold
  • 60,526
  • 100
  • 215
  • 315
72
votes
9 answers

Find a row in dataGridView based on column and value

I have a dataGridView that has 3 columns: SystemId, FirstName, LastName that is bound using database information. I would like to highlight a certain row, which I would do using: dataGridView1.Rows[????].Selected = true; The row ID I however do…
Lukas
  • 2,885
  • 2
  • 29
  • 31
71
votes
12 answers

How to disable the ability to select in a DataGridView?

I want to use my DataGridView only to show things, and I want the user not to be able to select any row, field or anything from the DataGridView. How can I do this?
Mahdi Tahsildari
  • 13,065
  • 14
  • 55
  • 94
70
votes
8 answers

How to change the color of winform DataGridview header?

I have tried to do it without success. Is it possible ?
programmernovice
  • 3,841
  • 11
  • 43
  • 63
69
votes
8 answers

Refresh DataGridView when updating data source

What is the best way to refresh a DataGridView when you update an underlying data source? I'm updating the datasource frequently and wanted to display the outcome to the user as it happens. I've got something like this (and it works), but setting…
shaunf
  • 1,063
  • 4
  • 10
  • 11
68
votes
3 answers

How do I remove the empty row from the bottom of a DataGridView control?

When I fill a DataGridView with data, there is always an empty row at the bottom. How do I disable this?
Luke
  • 5,771
  • 12
  • 55
  • 77
68
votes
12 answers

Right click to select a row in a Datagridview and show a menu to delete it

I have few columns in my DataGridView, and there is data in my rows. I saw few solutions in here, but I can not combine them! Simply a way to right-click on a row, it will select the whole row and show a menu with an option to delete the row and…
Data-Base
  • 8,418
  • 36
  • 74
  • 98
67
votes
6 answers

How to deselect all selected rows in a DataGridView control?

I'd like to deselect all selected rows in a DataGridView control when the user clicks on a blank (non-row) part of the control. How can I do this?
tinmac
  • 2,357
  • 3
  • 25
  • 41
62
votes
7 answers

Sort dataGridView columns in C# ? (Windows Form)

I have a datagridview that i bind from an sql table, in that dv i have those attributes: Id, Name and Price. When i set the SortMode of the Name Columns to Automatic and i click on the header of this column i can sort this dv based on the first…
AXheladini
  • 1,776
  • 6
  • 21
  • 42
61
votes
7 answers

How to format DateTime columns in DataGridView?

I'm using a DataGridView with object data binding to display information about logging entities in a system, retrieved via SOAP from a remote service. One of the columns is called "Last action" and means the last time the entity logged a message. It…
usr-local-ΕΨΗΕΛΩΝ
  • 26,101
  • 30
  • 154
  • 305
60
votes
13 answers

Show row number in row header of a DataGridView

Is it possible to show row number in the row header of a DataGridView? I'm trying with this code, but it doesn't work: private void setRowNumber(DataGridView dgv) { foreach (DataGridViewRow row in dgv.Rows) { row.HeaderCell.Value =…
davioooh
  • 23,742
  • 39
  • 159
  • 250