Ananth
Ananth

Reputation: 10730

Need to Disable a column in a Data Grid View in Winform

I have a data grid view ( say 5 columns ) . User has the option to disable/enable 1 particular column of the data table (using radio buttons). So How should I go about doing it?

When I select to disable the column, I need to make it non editable, change the color of the column so that user can understand that the column is disabled and any other suggestion are also welcome.

Upvotes: 6

Views: 32973

Answers (3)

Maria Sheikh
Maria Sheikh

Reputation: 87

I also came across the same problem,and its sol. for me is:

 int n = Convert.ToInt32(dataGridView3.Rows.Count.ToString());
         for (int i = 0; i < n; i++)
         {
             dataGridView3.Rows[i].Cells[0].ReadOnly = true;
         }

And it really worked for me.Works good when you are not going to declare columns name in datagridview and bringing it from any database.

Upvotes: 1

shanmuganathan
shanmuganathan

Reputation: 11

Your GridView control exposes the Columns property. Through these objects you can set properties (including visibility) for the individual columns. Example:

GridView.Columns[6].visible=false;

Upvotes: -1

Hans Passant
Hans Passant

Reputation: 942518

Set the column's ReadOnly property to true to make it non-editable. And alter its DefaultCellStyle.BackColor (and/or ForeColor) to make it obvious to the user.

Upvotes: 13

Related Questions