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
185
votes
20 answers

How to add a new row to datagridview programmatically

if add row to DataTable DataRow row = datatable1.NewRow(); row["column2"]="column2"; row["column6"]="column6"; datatable1.Rows.Add(row); How about DataGridView??
LK Yeung
  • 3,462
  • 5
  • 26
  • 39
170
votes
20 answers

How to change row color in datagridview

I would like to change the color of a particular row in my datagridview. The row should be changed to red when the value of columncell 7 is less than the value in columncell 10. Any suggestions on how to accomplish this?
EB.
  • 2,627
  • 8
  • 35
  • 55
159
votes
14 answers

How to handle click event in Button Column in Datagridview?

I am developing a windows application using C#. I am using DataGridView to display data. I have added a button column in that. I want to know how can I handle click event on that button in DataGridView.
Himadri
  • 2,922
  • 5
  • 32
  • 56
141
votes
7 answers

Selecting a row in DataGridView programmatically

How can I select a particular range of rows in a DataGridView programmatically at runtime?
Nagendra
  • 1,645
  • 4
  • 12
  • 14
134
votes
8 answers

right click context menu for datagridview

I have a datagridview in a .NET winform app. I would like to rightclick on a row and have a menu pop up. Then i would like to select things such as copy, validate, etc How do i make A) a menu pop up B) find which row was right clicked. I know i…
user34537
131
votes
25 answers

How do you automatically resize columns in a DataGridView control AND allow the user to resize the columns on that same grid?

I am populating a DataGridView control on a Windows Form (C# 2.0 not WPF). My goal is to display a grid that neatly fills all available width with cells - i.e. no unused (dark grey) areas down the right and sizes each column appropriately according…
Stuart Helwig
  • 9,318
  • 8
  • 51
  • 67
119
votes
20 answers

How to detect DataGridView CheckBox event change?

I have a winforms app and want to trigger some code when a checkbox embedded in a DataGridView control is checked / unchecked. Every event I have tried either Triggers as soon as the CheckBox is clicked but before its checked state changes,…
PJW
  • 5,197
  • 19
  • 60
  • 74
116
votes
8 answers

Filtering DataGridView without changing datasource

I'm developing user control in C# Visual Studio 2010 - a kind of "quick find" textbox for filtering datagridview. It should work for 3 types of datagridview datasources: DataTable, DataBinding and DataSet. My problem is with filtering DataTable from…
mj82
  • 5,193
  • 7
  • 31
  • 39
116
votes
12 answers

Index of Currently Selected Row in DataGridView

It's that simple. How do I get the index of the currently selected Row of a DataGridView? I don't want the Row object, I want the index (0 .. n).
ErikE
  • 48,881
  • 23
  • 151
  • 196
113
votes
5 answers

Binding List to DataGridView in WinForm

I have a class class Person{ public string Name {get; set;} public string Surname {get; set;} } and a List to which I add some items. The list is bound to my DataGridView. List persons = new…
namco
  • 6,208
  • 20
  • 59
  • 83
108
votes
10 answers

DataGridView AutoFit and Fill

I have 3 columns in my DataGridView. What I am trying to do is have the first 2 columns auto fit to the width of the content, and have the 3rd column fill the remaining space. Is it possible to do in WinForms? I am loading my data from an EF…
James Jeffery
  • 12,093
  • 19
  • 74
  • 108
104
votes
5 answers

Button in a column, getting the row from which it came on the Click event handler

I've set the itemsource of my WPF Datagrid to a List of Objects returned from my DAL. I've also added an extra column which contains a button, the xaml is below.
RekrowYnapmoc
  • 2,166
  • 2
  • 22
  • 23
102
votes
2 answers

List vs BindingList Advantages/DisAdvantages

Can someone describe what the difference between the two are for my project. Currently I have a List and set the BindingSource to that and a DataGridView to the BindingSource. I have implemented IEditableObject so when CancelEdit is called…
Jon
  • 38,814
  • 81
  • 233
  • 382
96
votes
2 answers

Datagridview - remove part before the first column

I was wondering if when using the datagridview control you can remove the thing that looks like a column before the 1st column. I think its used to select rows but not sure what its called.
Grant
  • 11,138
  • 32
  • 94
  • 140
93
votes
9 answers

How do I make the DataGridView show the selected row?

I need to force the DataGridView to show the selected row. In short, I have a textbox that changes the DGV selection based on what is typed into the textbox. When this happens, the selection changes to the matching row. Unfortunately if the…
kereberos
  • 1,253
  • 1
  • 10
  • 20
1
2 3
99 100