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
37
votes
3 answers

Make it possible to ONLY select one row in datagrid?

I want my datagrid to only allow one row to selected. I guess I can do this by adding code to the datagridviews selectionChanged-event, but is there a better solution? I would prefer to just have a property to set, i.e. : …
Sebastian Larsson
  • 371
  • 1
  • 3
  • 3
37
votes
7 answers

Datagridview: How to set a cell in editing mode?

I need to programmatically set a cell in editing mode. I know that setting that cell as CurrentCell and then call the method BeginEdit(bool), it should happen, but in my case, it doesn't. I really want that, with my DGV with several columns, the…
josecortesp
  • 1,526
  • 4
  • 21
  • 38
36
votes
13 answers

Changing datagridview cell color based on condition

I have loaded the data from database to datagridview and have two columns target value and volume where volume >target value that volume cell should be in green color and volume < target value then volume should be in red color. I tried it but I…
preethi
  • 885
  • 5
  • 20
  • 39
36
votes
7 answers

How to set column header text for specific column in Datagridview C#

How to set column header text for specific column in Datagridview C#
Mark
35
votes
15 answers

Triggering a checkbox value changed event in DataGridView

I have a grid view that has a check box column, and I want to trigger a drawing event as soon as the value of the cell is toggled. I tried the ValueChaged and the CellEndEdit and BeginEdit, and chose the selection mode as CellSelect. As for the the…
mustafabar
  • 2,317
  • 6
  • 31
  • 47
35
votes
9 answers

how I can show the sum of in a datagridview column?

I need to show the sum of the count column from this datagridview, but I don't know how I can get to the data in the datagridview. When I click on the button, I want to show 94 in label1. How can this be done?
mahnaz
  • 511
  • 1
  • 5
  • 10
35
votes
6 answers

How do I change the datagridview selected row background color?

How do I change the datagridview selected row background color in C# windows applications?
Lawrance Rozario
  • 461
  • 2
  • 5
  • 15
34
votes
3 answers

Showing tool tip for every item in datagridview row when mouse is above it

How can you show the tooltip for datagridview for every item in datagridview when you hover mouse over the item in that particular row? I have table product with columns: product name product price product description product image .... I have a…
Glory Raj
  • 17,397
  • 27
  • 100
  • 203
33
votes
3 answers

DataGridView: how to focus the whole row instead of a single cell?

I'd like to use the DataGridView control as a list with columns. Sort of like ListView in Details mode but I want to keep the DataGridView flexibility. ListView (with Details view and FullRowSelect enabled) highlights the whole line and shows the…
Tomas Sedovic
  • 42,675
  • 9
  • 40
  • 30
33
votes
4 answers

How do I get a DataRow from a row in a DataGridView

I'm using a databound Windows Forms DataGridView. how do I go from a user selected row in the DataGridView to the DataRow of the DataTable that is its source?
33
votes
12 answers

Populate a datagridview with sql query results

I'm trying to present query results, but I keep getting a blank data grid. It's like the data itself is not visible Here is my code: private void Employee_Report_Load(object sender, EventArgs e) { string select = "SELECT * FROM…
user2023203
  • 546
  • 1
  • 12
  • 19
33
votes
2 answers

How could I Drag and Drop DataGridView Rows under each other?

I've DataGridView that bound a List and i sort it by "Priority" property in "myClass". So I want to drag an "DataGridViewRow" to certain position to change it's "Priority" property. How could I "Drag & Drop" DataGridView Rows ?. And how to…
Wahid Bitar
  • 13,776
  • 13
  • 78
  • 106
32
votes
1 answer

Binding Entity Framework objects to a Datagridview C#

I have been trying to bind an Entity Framework object to a DataGridView but I keep hitting dead ends and I can't seem to find my answer anywhere. I can bind the whole of a table (entity) to a gridview and it will allow me to make changes and save…
Jimbo James
  • 727
  • 2
  • 9
  • 17
32
votes
7 answers

Why is my bound DataGridView throwing an "Operation not valid because it results in a reentrant call to the SetCurrentCellAddressCore function" error?

When binding a DataGridView control to a binding source, I'm getting the following error in my application: Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function The binding source depends on the…
priyanka
  • 543
  • 4
  • 10
  • 18
32
votes
1 answer

Retrieving selected row in dataGridView as an object

I have a class like this: public partial class AdressBokPerson { public long Session { get; set; } public string Förnamn { get; set; } public string Efternamn { get; set; } public string Mail { get; set; } …
Dimo
  • 3,238
  • 6
  • 29
  • 46