• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 118
  • Last Modified:

Using ReadOnly with a DataGridView?

The following code isn't working:

dataGridView1.ReadOnly = True
dataGridView1.Columns(1).ReadOnly = False

Open in new window

The above code doesn't allow me to enter data manually in Column 1 of the dgv.

I have a dgv that contains 15 columns and I only want to 2 of them to be able to enter data manually. I'm doing the above method just to save lines of code (not that big of deal really). Just wondered if there was a way of doing this without having to set all the Columns.ReadOnly = True?

1 Solution
A cell is read-only if the value of the ReadOnly property is true for the cell, the cell's row, the cell's column, or the DataGridView.

Implies that a cell is read-only if it or any of it's parent containers have the ReadOnly property set to true.

So to answer your question directly, you will have to explicitly define the ReadOnly property for each of the cells that you want to be read-only and set the ReadOnly property of the GridView to false.

BlakeMcKennaAuthor Commented:
Thanks for the clarification!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now