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

How to add new DataRow into DataTable?

I have a DataGridView binded to a DataTable (DataTable binded to database). I need to add a DataRow to the DataTable. I'm trying to use the following code: dataGridViewPersons.BindingContext[table].EndCurrentEdit(); DataRow row =…
malcoauri
  • 11,904
  • 28
  • 82
  • 137
45
votes
8 answers

How can I bold the fonts of a specific row or cell in an Excel worksheet with C#?

I am exporting data from a List<> to excel. I want to make some specific rows and cells bold. I need to make some cell merged also. Below is the code I am using. try { Excel.Application application; Excel.Workbook…
user1665707
  • 615
  • 3
  • 11
  • 24
44
votes
10 answers

Disable Cell Highlighting in a datagridview

How to disable Cell Highlighting in a datagridview, Highlighting should not happen even if I click on the cell. Any thoughts please
Ramji
  • 2,536
  • 7
  • 34
  • 54
44
votes
7 answers

How to activate combobox on first click (Datagridview)

In winforms, you need to click the combobox twice to properly activate it - the first time to focus it, the second time to actually get the dropdown list. How do I change this behavior so that it activates on the very first click? This is for…
TtT23
  • 6,876
  • 34
  • 103
  • 174
44
votes
2 answers

Is there an Attribute I can use in my class to tell DataGridView not to create a column for it when bound to a List

I have a class like this: private class MyClass { [DisplayName("Foo/Bar")] public string FooBar { get; private set; } public string Baz { get; private set; } public bool Enabled; } When I create a List and assign it to the…
Blorgbeard
  • 101,031
  • 48
  • 228
  • 272
43
votes
13 answers

How to export dataGridView data Instantly to Excel on button click?

I have 10k rows and 15 column in my data grid view. I want to export this data to an excel sheet o button click. I have already tried with the below code. private void btExport_Click(object sender, EventArgs e) { …
Jake
  • 1,560
  • 2
  • 17
  • 25
42
votes
3 answers

How do I allow edit only a particular column in datagridview in windows application?

I want to enable only two columns in the DataGridview to be able to edit. The others should not be allowed to edit. Further I am not directly linking to datasource; I will be doing some thing like this way DataTable dt = new…
cmrhema
  • 981
  • 2
  • 16
  • 28
41
votes
2 answers

Scroll to bottom of C# DataGridView

I'm trying to scroll to bottom of a DataGridView in a C# WinForm. This code works with a TextBox: textbox_txt.SelectionStart = textbox_txt.Text.Length; textbox_txt.ScrollToCaret(); ... but I don't know how to do it with a DataGridView. Any help,…
Motumbo
  • 655
  • 1
  • 8
  • 12
40
votes
5 answers

Index was out of range. Must be non-negative and less than the size of the collection parameter name:index

I'm trying to add data as one by one row to a datagridview here is my code and it says: "Index was out of range. Must be non-negative and less than the size of the collection parameter name:index" What does this mean? What is the problem in my…
user2566013
  • 407
  • 1
  • 4
  • 4
40
votes
7 answers

C#: multiline text in DataGridView control

Is it possible for the DataGridView control to display multiline text in a cell? I am using Visual Studio 2005 and C#.
KeithDB
  • 415
  • 1
  • 4
  • 6
39
votes
5 answers

What event catches a change of value in a combobox in a DataGridViewCell?

I want to handle the event when a value is changed in a ComboBox in a DataGridView cell. There's the CellValueChanged event, but that one doesn't fire until I click somewhere else inside the DataGridView. A simple ComboBox SelectedValueChanged…
yurib
  • 8,043
  • 3
  • 30
  • 55
39
votes
14 answers

How to programmatically set cell value in DataGridView?

I have a DataGridView. Some of the cells receive their data from a serial port: I want to shove the data into the cell, and have it update the underlying bound object. I'm trying something like this: SetValueFromSerial (decimal newValue) { …
XXXXX
  • 1,076
  • 1
  • 8
  • 13
38
votes
10 answers

How can I refresh c# dataGridView after update ?

I have a dataGridView when I click on any row a form is opened to update the row data, but after ending updates the updating form is closed but the dataGridView data is not updated How can i do that ?
amer
  • 613
  • 3
  • 7
  • 10
38
votes
3 answers

Using a list as a data source for DataGridView

I've extracted the setting names and their respective values out of a configuration file into an ordered dictionary. The dictionary contains keys and values which are of the ICollection class. I want to bind that data and display it in a…
tf.rz
  • 1,347
  • 6
  • 18
  • 47
38
votes
5 answers

Changing datagridview cell color dynamically

I have a dataGridView object that is populated with data. I want to click a button and have it change the color of the background of the cell. This is what I currently have foreach(DataGridViewRow row in dataGridView1.Rows) { …
fifamaniac04
  • 2,343
  • 12
  • 49
  • 72