?
Solved

Is it possible to make Rows in a DataGridView read only upon an Edit

Posted on 2011-02-28
8
Medium Priority
?
584 Views
Last Modified: 2013-11-26
I have a datagrid that is editable. I want to lock all rows in the grid when a person edits a row so that they can only change the row that they are editing. This way they can only change one row in the grid and be forced to save before changing anything else.

Does anyone have any pointers on how to do this?
0
Comment
Question by:imonfireDAMMIT
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 17

Expert Comment

by:nepaluz
ID: 34998338
unless you have asked your question wrongly, the functionality that you ask for ships with the datagridview. You literally can NOT edit 2 cells at any one time, let alone two rows!
0
 
LVL 16

Expert Comment

by:13598
ID: 34998378
Instead of forcing them to save the changes from one row before editing another one why don't you set your grid to automatically save on row exit. You could add a messagebox if the user can change his/her mind at the last minute asking them if they really want to save it. If yes save changes if no cancel save changes.
0
 
LVL 1

Author Comment

by:imonfireDAMMIT
ID: 34998389
OK let me re-ask this...

Once a row has been edited i want all the other rows to be locked so they cant edit them.

So if they click on another row, that row is read only...
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 1

Author Comment

by:imonfireDAMMIT
ID: 34998435
Im making a Wizard and that dataset associated with the datagrid  will not be saved till the end, it gives them a chance to cancel all changes. The wizard requires them to select and edit a row from a project but I do not want them changing two projects at once. They should know that but you know users, I'll get a guy changing stuff everywhere and wonder why his data is all screwed up. I try to account for all the things the users are going to try to do, so that my job is easier in the end :-)
0
 
LVL 16

Expert Comment

by:13598
ID: 34998543
Then yes you can lock the other rows by iterating through all rows changing them to readonly except for the current row.
0
 
LVL 16

Accepted Solution

by:
13598 earned 2000 total points
ID: 34998655
Depending on the rest of your code you could put something like this either on your rowleave or rowvalidating event:
  If Me.DataGridView.IsCurrentRowDirty then
For Each myRow As DataGridViewRow In Me.DataGridView.Rows
 If myRow.Index <> e.RowIndex Then
                    myRow.ReadOnly = True
                End If
next
end if
0
 
LVL 1

Author Comment

by:imonfireDAMMIT
ID: 34998844
ok THANK YOU! I was just about to ask which event to use. I think it would probably be better in the row leave. I will apply this and let you know how it works. It seems right. I always have a hard time figuring out which event to use...there are so many
0
 
LVL 1

Author Closing Comment

by:imonfireDAMMIT
ID: 34999197
Thank you!!! You saved me a lot of work. My method that I was trying to implement was pretty lengthy and rediculous compared to this :-)
0

Featured Post

Give Your Engineering Team a Productivity Boost

Learn why container technology is so powerful and how it can provide your team with productivity gains and other benefits.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question