Start Free Trial
Come for the solution, stay for everything else.
Start Free Trial
How to set cells in datagridview to readonly and BackColor upon construction
I'd tried to set some cells in a datagridview to readonly and their BackColor to grey upon construction of a UserControl. But they didn't take effect.
I'd done some searches. It was said that it needs to be done inside "CellBeginEdit". My question is how to get that event to fire as part of the construction. Any other suggestion is welcomed.
Thanks in advance.
8/22/2022 - Mon
check this fro readonly
Protected Sub GridView1_RowDataBound(ByV
al sender As Object, ByVal e As System.Web.UI.WebControls.
) Handles GridView1.RowDataBound
If e.Row.RowState = DataControlRowState.Edit And (e.Row.RowIndex = 0 Or e.Row.RowIndex = 1) Then
e.Row.RowState = DataControlRowState.Normal
to change backcolr try this
I am using C# .NET, and I can't find the equivalent of your suggestion. The two lines I currently have in my code are:
They don't work during construction but can only work during cell edit mode.
y = true;
ackColor = Color.LightGray;
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
By the way, my dgv is bound to a DataSource.
Can you explain what you mean by "They don't work during construction but can only work during cell edit mode."?
What I have is a dgv. This dgv is on a UserControl and is displayed only when a user initiated it (eg. clicking a treenode). ie. at run-time.
This dgv consists of two columns, and is data-binded to a DataSource.
Dependent upon the value on the left-hand side column, the corresponding entry on the right-hand column will be made either editable with a white background, or readonly with a grey background.
What I meant by "don't work during construction" is when user clicks a node to initiate the UserControl construction. It constructs the dgv, creates the data-binding, checks each entry on the left-hand side column and sets the right-hand side column accordingly.
Unfortunately, making them readonly and setting the background color did not take any effect at all.
On the other hand, after it is constructed when I edit a cell on the left-hand side column (eg. changing selection), I could make the corresponding cell on the right-hand side readonly with grey background color.
Your help will be appreciated. Thanks in advance.
to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
I'd tried out with a simple example but this one works fine.
Any idea what could cause the setting on the properties BackColor and ReadOnly not to take any effect?
ASKER CERTIFIED SOLUTION
Log in or sign up to see answer
Become an EE member today
7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
It resolved the issue
Plans and Pricing
Certified Expert Program
© 1996-2023 Experts Exchange, LLC. All rights reserved. Covered by US Patent