Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8404647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:39:07+00:00 2026-06-09T22:39:07+00:00

I have a datagridview in a WinForms application and I want all columns bar

  • 0

I have a datagridview in a WinForms application and I want all columns bar one to be locked to editing. This I was able to achieve with the following code:

foreach (DataGridViewColumn col in myGrid.Columns)
{
    if (col.Name == "LockedColumn")
    {
        col.ReadOnly = false;
    }
    else
    {
        col.ReadOnly = true;
    }
}  

However, I also need a conditional lock on this column, dependent on the values elsewhere in each row. I tried the following code:

foreach (DataGridViewRow row in myGrid.Rows)
{
    if ((bool)row.Cells["ConditionalColumn"].Value == false)
    {
        row.ReadOnly = false;
    }
    else
    {
        row.ReadOnly = true;
    }
}     

However this locks the whole grid which is not what I want. What I’m after may be clearer with a table example.

ColA ColB ColC

row1 true value1

row2 false value2

row3 true value3

I want Columns A & B locked (read only) in their entirety, and the default for Col C to allow editing, except where the value in Column B is false. Hence in the above example only value1 and value3 would be editable.

However I can’t seem to achieve this, because as stated above, if I loop through the rows with a condition that sets readonly to false, everything is locked.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T22:39:08+00:00Added an answer on June 9, 2026 at 10:39 pm

    It was the following line that was the issue

    row.ReadOnly = false;
    

    When changed to

    row.Cells["colName"].ReadOnly = false;
    

    it works as intended

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DataGridView in a Winforms application. I want to select a set
i have a winforms application and i want to export data from the datagridview
I have a DataGridView with one DataGridViewComboBoxColumn in my WinForms application. I need to
I have a WinForms application with DataGridView control. My control has five columns (say
ALL, I have a DataGridView control on my WinForms application with the selection property
i am working on a DataGridView in C# 3.5, in winforms application. I have
I have a winforms datagridview that seems to always have at least one row
I have a DataTable which is bound to datagridview (Winforms)... I use the following
I have a DataGridView in a Winforms application containing a collection of items. Each
I have a datatable bound to a winforms dataGridView via a BindingSourceControl. I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.