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
21
votes
4 answers

How to refresh datagridview when closing child form?

I've a dgv on my main form, there is a button that opens up another form to insert some data into the datasource bounded to the dgv. I want when child form closes the dgv auto refresh. I tried to add this in child form closing event, but it doesn't…
DanSogaard
  • 712
  • 5
  • 13
  • 27
21
votes
8 answers

C# refresh DataGridView when updating or inserted on another form

I have 2 forms which are form A and form B, form A allowes user to insert and update student information. form b is only a DataGridView and button there. When I insert student on form A, then I go to form B, the new student did not show on the…
Tham JunKai
  • 259
  • 2
  • 4
  • 11
21
votes
2 answers

DataGridView automatic sorting doesn't work when datasource bound

My problem is: when I bind datasource to DataGridView BindingList contracts = new BindingList(Contract.GetAll()); dgEndingContracts.DataSource = contracts.Where(c => c.ExpirationDate <= nextMonth && c.IsArchived ==…
mandrive
  • 1,005
  • 1
  • 10
  • 13
21
votes
2 answers

How can I use LINQ to find a DataGridView row?

Is there any way to use a LINQ style query to find a DataGridView row? I am trying to find the one bound to a specific object and highlight it. MyDatagrid.Rows.FirstOrDefault(r => r.DataBoundItem == myItem).Selected = true; Error 1 …
Darrin Doherty
  • 840
  • 1
  • 6
  • 17
21
votes
12 answers

LINQ: custom column names

UPDATE I'm basically binding the query to a WinForms DataGridView. I want the column headers to be appropriate and have spaces when needed. For example, I would want a column header to be First Name instead of FirstName. How do you create your own…
Bryan Roth
  • 10,479
  • 15
  • 47
  • 56
20
votes
4 answers

Is it possible to prevent a multi line HeaderText in a DataGridView?

When the length of the HeaderText property reaches a certain character limit and there is a space in the text, WinForms automatically inserts a link break in the header: What I want: +-----------------------+--- | Measurement Value (%) |…
xsl
  • 17,116
  • 18
  • 71
  • 112
20
votes
4 answers

DataGridView setting Row height in code and disable manual resize

In my grid I had following line of code which disabled user's manual resizing: dgvTruckAvail.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; Now I needed to set column height in code and it didn't work (see DataGridView setting row height…
katit
  • 17,375
  • 35
  • 128
  • 256
20
votes
4 answers

how to change color of a column in datagridview?

I have a DataGridview, and I'm setting some of the columns to readonly for data entry purposes. When I do that, the column stays the normal white (although it does not allow entry). How can I color the column gray? I've seen lots of samples on…
MAW74656
  • 3,449
  • 21
  • 71
  • 118
20
votes
3 answers

Open dropdown(in a datagrid view) items on a single click

How can i avoid the double click on a DropDownButton used within a DataGridView? Right now I am able to view the drop down items within the DataGridView by clicking two or more times. First time it selects the cell and second time when I click on…
NewBie
  • 1,824
  • 8
  • 35
  • 66
20
votes
10 answers

How to prevent going to next row after editing a DataGridViewTextBoxColumn and pressing EnterKey?

I'm working on a program with DataGridViews. In one DatagridView there is a DataGridViewTextBoxColumn, which is enabled to be edited by the user. When the user is done with typing the numbers into it, he presses ENTER on the keyboard. Now the…
Max
  • 502
  • 2
  • 4
  • 14
20
votes
7 answers

How to highlight a DataGridView row or make it glow temporarily?

Using a C# DataGridView how can I: Highlight a row Make a row glow temporarily (go yellow for a couple of seconds)
Craig Johnston
  • 7,467
  • 16
  • 40
  • 47
20
votes
6 answers

How to improve painting performance of DataGridView?

(sorry for bad English) I have a big problem with performance of DataGridView when it re-paints. I'm using a DataGridView to show logs from an external application stream. Messages from the stream come in with a high frequency (less than 1 ms). If I…
Yuriy
  • 2,670
  • 6
  • 33
  • 48
20
votes
7 answers

How to manually drop down a DataGridViewComboBoxColumn?

I have a DataGridView with one DataGridViewComboBoxColumn in my WinForms application. I need to drop down (open) this DataGridViewComboBoxColumn manually, let's say after a button is clicked. The reason I need this is I have set SelectionMode to…
user20353
  • 1,293
  • 4
  • 15
  • 28
20
votes
5 answers

DataGridView throwing "InvalidOperationException: Operation is not valid..." when adding a row

I want an OpenFileDialog to come up when a user clicks on a cell, then display the result in the cell. It all works, except that the DataGridView displays an extra row, for adding values to the list it's bound to. The row shows up if…
BlueRaja - Danny Pflughoeft
  • 84,206
  • 33
  • 197
  • 283
20
votes
14 answers

DataGridView without selected row at the beginning

In my WinForms I have DataGridView. I wanted to select full row at once so I set SelectionMode as FullRowSelect. And now I have problem, because at the beginning my form underlines first row (set of selected rows is empty, the first row is not…
Peter
  • 912
  • 3
  • 11
  • 29