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 8749947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:46:45+00:00 2026-06-13T12:46:45+00:00

In my datagridview, I have got some columns are read only , so i

  • 0

In my datagridview, I have got some columns are read only, so i have given in some color.
When I load the the DGV in advance view with all columns including read only.
When the user cliks on Normal View I want to just display the normal eitable cols and hide the read only columns and the color.

I’m on telerik and using radgrid.

I tried the below approach but it’s not working. Is there any better way of doing this?? Thank you.

private void normalToolStripMenuItem_Click(object sender, EventArgs e)//Normal View
{
    DTURradGridView.Columns[2].IsVisible = false;
    DTURradGridView.Columns[3].IsVisible = false;
    DTURradGridView.Columns[4].IsVisible = false;
    DTURradGridView.Columns[5].IsVisible = false;
    DTURradGridView.Columns[7].IsVisible = false;
    DTURradGridView.Columns[11].IsVisible = false;

    DTURradGridView.Columns[2].ReadOnly = false;
    DTURradGridView.Columns[3].ReadOnly = false;
    DTURradGridView.Columns[4].ReadOnly = false;
    DTURradGridView.Columns[5].ReadOnly = false;
    DTURradGridView.Columns[7].ReadOnly = false;
    DTURradGridView.Columns[11].ReadOnly = false;

    DTURradGridView.CellFormatting -= DTURradGridView_CellFormatting;
}

private void advancedToolStripMenuItem_Click(object sender, EventArgs e) //Advanced View
{
    DTURradGridView.Columns[2].IsVisible = true;
    DTURradGridView.Columns[3].IsVisible = true;
    DTURradGridView.Columns[4].IsVisible = true;
    DTURradGridView.Columns[5].IsVisible = true;
    DTURradGridView.Columns[7].IsVisible = true;
    DTURradGridView.Columns[11].IsVisible = true;

    DTURradGridView.Columns[2].ReadOnly = true;
    DTURradGridView.Columns[3].ReadOnly = true;
    DTURradGridView.Columns[4].ReadOnly = true;
    DTURradGridView.Columns[5].ReadOnly = true;
    DTURradGridView.Columns[7].ReadOnly = true;
    DTURradGridView.Columns[11].ReadOnly = true;

    DTURradGridView.CellFormatting += DTURradGridView_CellFormatting;   
}

private void DTURradGridView_CellFormatting(object sender, CellFormattingEventArgs e)
{
    if (e.CellElement.ColumnIndex != 2 && e.CellElement.ColumnIndex != 3 && e.CellElement.ColumnIndex != 4
    && e.CellElement.ColumnIndex != 5 && e.CellElement.ColumnIndex != 7 && e.CellElement.ColumnIndex != 11) return;

    e.CellElement.DrawFill = true;
    e.CellElement.NumberOfColors = 1;
    e.CellElement.BackColor = Color.LightSlateGray;
    e.CellElement.GradientStyle = GradientStyles.Linear;    
}

When I click on the normal view, I see the colors of the col index 2,3,4,5. So the -= is not working.

  • 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-13T12:46:45+00:00Added an answer on June 13, 2026 at 12:46 pm

    The better approach would be to set read-only columns and their color once at form startup, preferably by name. See How to change color of a column in datagridview?

    Then iterate through columns and hide or show those which are readonly, depending on which mode you are in. Having it hard-coded like this is not a good practice:

    DTURradGridView.Columns[2].ReadOnly = true;
    DTURradGridView.Columns[3].ReadOnly = true;
    DTURradGridView.Columns[4].ReadOnly = true;
    

    Who knows what’s 2, 3, 4? Nobody. Problem is you can easily get lost in your own code.

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

Sidebar

Related Questions

I've got some Columns in a DataGridView that have their Binding property set to
I have datagridview with checkbox column, but I want, that some of the columns
I have a DataGridView with some columns in it. For example I have the
In my datagridview, i got 4 columns and a textbox to search. I have
Some event handlers for the WinForm DataGridView have DataGridViewCellEventArgs as a parameter and a
I have DataGridView with two columns. The first column is TextBoxCol(DataGridViewTextBoxColumn) and the Second
In My DatagridView ,I Have Two Columns, ComboxboxColumn and TextboxColumn . I want to
Hi I got a DatagridView and I would like it to change background color
I have a windows forms application with a DataGridView (DGV) on part of it.
I have a DataGridView I also have some tableAdapters (groupTableAdapter, userTableAdapter) generated from sqlserver

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.