Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 DataTable(); dt.Columns.Add("Email"); dt.Columns.Add("email1"); for (int i = 0; i < 5; i++) {     DataRow dr = dt.NewRow();     dr["Email"] = i.ToString();     dr["email1"] = i.ToString() + "sdf";     dt.Rows.Add(dr); } BindingSource bs = new BindingSource(); bs.DataSource = dt; dataGridView1.DataSource = bs; 

So which property should I set, that will enable only one column say Email(in the above eg) to be editable.

like image 550
cmrhema Avatar asked Apr 08 '10 02:04

cmrhema


People also ask

How set DataGridView cell in Edit mode?

By default, users can edit the contents of the current DataGridView text box cell by typing in it or pressing F2. This puts the cell in edit mode if all of the following conditions are met: The underlying data source supports editing.

How do I make DataGrid read-only?

To make a column read-only programmaticallySet the DataGridViewColumn. ReadOnly property to true .

What is difference between DataGridView and DataGrid control in Winforms?

The DataGrid control is limited to displaying data from an external data source. The DataGridView control, however, can display unbound data stored in the control, data from a bound data source, or bound and unbound data together.

What is the use of DataGridView control?

The DataGridView control provides a powerful and flexible way to display data in a tabular format. You can use the DataGridView control to show read-only views of a small amount of data, or you can scale it to show editable views of very large sets of data.


1 Answers

Set the ReadOnly property of the other columns to true.

(You'll probably need to loop through the Columns collection and use an if statement)

like image 168
SLaks Avatar answered Oct 08 '22 21:10

SLaks