473,385 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Protect a field (property?)

From a C# program I have selected a specific SQL database record which I want to display on a Windows form. However, even though I wish to display all the fields in the database record for visual confirmation that I do indeed have the correct record there is only one field I wish to change. So, to prevent accidental updating of all other fields, I wish to protect these fields and only allow the user access to the one field I want updated. Can anyone point me in the right direction?
Thanks.
Jun 16 '11 #1

✓ answered by Curtis Rutland

Depends on how you're displaying these fields. If you're just using normal GUI controls, use Labels to display the read-only fields. You can't edit a label. Or use a TextBox, and set it's ReadOnly property to true.

If you're using a DataGrid, there are ways to set columns to read only. You have to manually add the columns though, not auto-generate them.

6 1771
Curtis Rutland
3,256 Expert 2GB
Depends on how you're displaying these fields. If you're just using normal GUI controls, use Labels to display the read-only fields. You can't edit a label. Or use a TextBox, and set it's ReadOnly property to true.

If you're using a DataGrid, there are ways to set columns to read only. You have to manually add the columns though, not auto-generate them.
Jun 16 '11 #2
Thanks Curtis, I'll set the ReadOnly property. One other question, how do I close the current form and return to a previous calling form?

Joe
Jun 17 '11 #3
Curtis Rutland
3,256 Expert 2GB
Again, depends. How did you create the new form (Show or ShowDialog)? Did you close the old form when you opened the new one? Hide it? Nothing?

You can call .Close() on a form and it will close.
Jun 17 '11 #4
I did a .Show, and I didn't do anything with the old form. It was only after googling that I realised it might be a good idea to close it. On a button1_Click event I tried form1.Close(); but it gave me an error "An object reference is required for the non-static field, method, or property..." Also, I'm intrigued by the "Hide" method you mentioned... so much new stuff to learn :-) Anyway, once again many thanks, I'm amazed at how many nice people there are in the IT fraternity, gives me hope in humanity. Joe
Jun 17 '11 #5
Curtis Rutland
3,256 Expert 2GB
Well, if you want to hide the form, you would use .Hide.

The problem is, if you're using Show, then your Form1 has no idea when it should show itself. You have to use events. Subscribe to the child form's Closed event, and call "this.Show()" to bring it back.
Jun 17 '11 #6
Thank you, not 100% sure how to do that but now you have pointed me in the right direction it's amazing what one can find out with GOOGLE. :-)
Jun 18 '11 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: LaurenW | last post by:
Hi folks, I just discovered that I have a table with a bunch of text fields that ALL have the "Allow Zero Length" property set to "No", which is apparently the default when you create a new text...
4
by: John Baker | last post by:
Hi: I am having a problem making the impact a field property change in a table trickle through to a report. Between the table and the report are numerous queries and sums. I have changed the...
0
by: Bruce LeMond | last post by:
To my understanding the data key field property in the web form datagrid is used for finding the correct record in the data set for updating. It looks like only one field could be specified, but...
8
by: MilanB | last post by:
Hello What is the best way (or does it exists a way at all) to protect WinForm application from decompiling IL. Can it be full compiled yo windows native before distribution. And what is...
15
by: Lauren Wilson | last post by:
Owning your ideas: An essential tool for freedom By Daniel Son Thinking about going into business? Have an idea that you think will change the world? What if you were told that there was no way...
1
by: naseesalih | last post by:
i write code for protect selection of field. its working properly in explorer but not working in Netscape or other browser. pls send any one who know how to write netscape function...
3
by: zlfcn | last post by:
Hi all, In java, if a field is Integer type, we can assign it to null indicating that this field has not been set yet. How can we achieve that in C#? In C#, "int" is struct, we cannot set it to...
6
by: questionit | last post by:
If we have 2 tables, which are linked to each other And i want to change property of a field in one of the tables i.e Max Character Length, etc how would i do it - becasue Ms Access doesn't us...
1
by: Tirisano | last post by:
I am getting the following error in a ASP.Net application. A field or property with the name 'ContactPerson' was not found on the selected datasource. We are running SQL Server 2000. We are...
0
by: Clive Dixon | last post by:
Is there any way in code snippets that I can have a single replacement field from which I can generate both a field name and a property name along the standard lines, i.e. camle case & Pascal case...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.