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
57
votes
7 answers

How do I select a complete dataGridView Row when the user clicks a cell of that row?

I have a dataGridView and I need that when the user clicks on any cell the whole row that contains this cell is selected too. (it has multiselect disbaled) I tried getting the currentRowIndex like this int Index =…
Alex Terreaux
  • 1,881
  • 5
  • 23
  • 39
56
votes
10 answers

DataGridView - Focus a specific cell

How to set focus on any specified cell in DataGridView? I was expecting a simple way like Focus(rowindex,columnindex) but it is not that easy.
SMUsamaShah
  • 7,677
  • 22
  • 88
  • 131
56
votes
14 answers

DataGridView - how to set column width?

I have a WinForms application with DataGridView control. My control has five columns (say "Name", "Address", "Phone" etc) I am not happy with default column width. I want to have more control over column appearance. What I want is to be able to do…
Captain Comic
  • 15,744
  • 43
  • 110
  • 148
54
votes
18 answers

Datagridview full row selection but get single cell value

I have a datagridview that is a full row select. How would I grab the data from only a certain cell no matter what cell in the row was clicked on since it highlights the entire row.
Tsukasa
  • 6,342
  • 16
  • 64
  • 96
54
votes
21 answers

How to delete a selected DataGridViewRow and update a connected database table?

I have a DataGridView control on a Windows Forms application (written with C#). What I need is: when a user selects a DataGridViewRow, and then clicks on a 'Delete' button, the row should be deleted and next, the database needs to be updated using…
Woody
  • 1,159
  • 3
  • 15
  • 25
53
votes
5 answers

How to set DataGridView textbox column to multi-line?

How to let "DataGridViewTextBoxColumn" in DataGridView supports Multiline property?
Wahid Bitar
  • 13,776
  • 13
  • 78
  • 106
51
votes
7 answers

Make a specific column only accept numeric value in datagridview in Keypress event

I need to make datagridview that only accept the numeric value for specific column only in keypress event. Is there any best way to do this?
Eplzong
  • 670
  • 1
  • 8
  • 13
50
votes
11 answers

WinForms DataGridView font size

How do I change font size on the DataGridView?
leora
  • 188,729
  • 360
  • 878
  • 1,366
50
votes
3 answers

How to disable the last blank line in DatagridView?

For C# Window Form, there is a tool called DataGridView. If we use that to display data, it shows an extra line. If we have 3 rows of data, it shows 4 rows. the 4th row is a blank row. I wanna know how to disable it.. or hide it?
william
  • 7,284
  • 19
  • 66
  • 106
50
votes
12 answers

Changing the row height of a DataGridView

How can I change the row height of a DataGridView? I set the value for the property but height doesn't change. Any other property has to be checked before setting this one.
karthik
  • 4,485
  • 8
  • 30
  • 45
50
votes
6 answers

DataGridView get current selected object

I need to get the currently selected object from da databound DataGridView. I do not need the object of the current selected cell, but the object on which the whole row is based, in this case a BusinessObject whos properties make the columns of the…
Oliver Friedrich
  • 9,018
  • 9
  • 42
  • 48
49
votes
13 answers

How to resize datagridview control when form resizes

I found a lot of questions about how to resize the form when a child control resizes, but I'm trying to do something much simpler (maybe so simple people don't even ask it :| ) I'd like to automatically resize my datagridview's width to fill the…
lowerkey
  • 8,105
  • 17
  • 68
  • 102
49
votes
5 answers

How to bind list to dataGridView?

I seem to be running around in circles and have been doing so in the last hours. I want to populate a datagridview from an array of strings. I've read its not possible directly, and that I need to create a custom type that holds the string as a…
Amc_rtty
  • 3,662
  • 11
  • 48
  • 73
47
votes
6 answers

How can I populate textboxes with data from a DataGridViewRow?

I have a DataGridView (Selectionmode: FullRowSelect) and some textboxes on a Windows Form. I want the contents of a row that is clicked (or double clicked) to be displayed in the textboxes. I tried out this code: private void…
Samy S.Rathore
  • 1,825
  • 3
  • 26
  • 43
46
votes
3 answers

Programmatically add new column to DataGridView

I have a DataGridView bound to a DataTable. The DataTable is populated from a database query. The table contains a column named BestBefore. BestBefore is a date formatted as a string (SQLite doesn't have date types). I would like to…
halfpint
  • 561
  • 1
  • 6
  • 10