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

Unable To set row visible false of a datagridview

I have a DataGridView where I set DataSource: taskerEntities te = new taskerEntities(); var OMsMasterDescriptiveIndicators = te.MyTable.Select(x => new lccls {Id = x.Id, name = x.name }).ToList(); MyGrid.DataSource =…
Amit Bisht
  • 4,870
  • 14
  • 54
  • 83
31
votes
8 answers

DataGridView bound to a Dictionary

I have a Dictionary that contains items and prices. The items are unique but slowly get added and updated through the lifetime of the application (that is, I don't know the item strings in advance). I would like to bind this structure to a…
WillH
  • 2,086
  • 6
  • 23
  • 40
31
votes
10 answers

How to hide column of DataGridView when using custom DataSource?

I have a small app in c#, it has a DataGridView that gets filled using: grid.DataSource = MyDatasource array; MyClass hold the structure for the columns, it looks something like this: class MyDatasource { private string column1; …
mglog
  • 311
  • 1
  • 3
  • 3
31
votes
10 answers

DataGridViewComboBoxCell Binding - "value is not valid"

I'm trying to bind separate ComboBox cells within a DataGridView to a custom class, and keep getting an error DataGridViewComboBoxCell value is not valid I'm currently assigning the data source for the cell to an IList from a…
Ian
  • 33,605
  • 26
  • 118
  • 198
31
votes
3 answers

Custom column names for DataGridView with associated DataSource

How can I setup custom column names for DataGridView with associated DataSource? Here is some code: class Key { public string Value { get; } public DateTime ExpirationDate { get; } } List keys = new List(); ...// fill keys…
Bobrovsky
  • 13,789
  • 19
  • 80
  • 130
31
votes
4 answers

DataGridView Row Height Autosize

I am using a DataGridView in C# .NET 3.5 and I want the height of all rows set to AutoSize. I set WrapMode = true but am still not getting the height to autosize.
Khilen Maniyar
  • 2,519
  • 7
  • 31
  • 35
31
votes
12 answers

DataGridView first column,first row, is selected on Load, I don't want this

So basically the very first column in the first row is always selected, I can't figure out a way to have it so the gridview has no selected cells. Any help?
Spooks
  • 6,937
  • 11
  • 49
  • 66
30
votes
9 answers

Unselect all rows in datagridview

I have two datagridviews, and when I click to one of them, I would like to deselect all selection in the second datagridview, I tried this, but nothing works: firstItemsDataGridView.ClearSelection(); firstItemsDataGridView.CurrentCell = null; not…
Martin Ch
  • 1,337
  • 4
  • 21
  • 42
30
votes
7 answers

How to find column name with column index in DataGridView?

I want to find column name in DataGridView. I have column index. How can I find it. dGVTransGrid.CurrentCell.ColumnIndex: I want it's column name. Plz help. Thanks.
Nagendra Kumar
  • 634
  • 2
  • 12
  • 20
30
votes
2 answers

Direct access to DataGridView combobox in one click?

I'm getting annoyed with clicking once to select a row in the datagridview, and then clicking again to click on a control in that row (in this case a combobox). Is there a way configure this thing so that all this can be done in one mouse click…
Isaac Bolinger
  • 7,328
  • 11
  • 52
  • 90
30
votes
3 answers

NullReferenceException when setting AutoSizeMode to AllCells in DataGridView

I am manually binding an entity framework code first table to a datagridview. When I set the AutoSizeMode to AllCells and add an instance to the table I get a NullReferenceException during Add. The code runs like…
30
votes
28 answers

VB.NET: Clear DataGridView

I've tried - DataGridView1.DataSource=Nothing and DataGridView1.DataSource=Nothing DataGridView1.Refresh() and DataGridView1.RefreshEdit() None of them works.. I've written a method that sets the DataSource of the DataGridView when executed. but…
Bibhas Debnath
  • 14,559
  • 17
  • 68
  • 96
30
votes
3 answers

Looping through each row in a datagridview

How do I loop through each row of a DataGridView that I read in? In my code, the rows won't bind to the next row because of the same productID, so the DataGridView won't move to a new row. It stays on the same row and overwrites the price (for some…
Ke Vin
  • 3,478
  • 11
  • 60
  • 91
30
votes
7 answers

c# datagridview doubleclick on row with FullRowSelect

I have a datagridview in my C# application and the user should only be able to click on full rows. So I set the SelectionMode to FullRowSelect. But now I want to have an Event which is fired when the user double clicks on a row. I want to have the…
Metalhead89
  • 1,740
  • 9
  • 30
  • 58
29
votes
10 answers

Best way to disable the column header sorting in DataGridView

I need to disable the column header sorting in DataGridView. We can do that by setting the property of individual columns like BalancesGridView.Columns[1].SortMode = DataGridViewColumnSortMode.NotSortable; If this is the case , then I'll have to…
Ananth
  • 10,330
  • 24
  • 82
  • 109