Solved

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

Posted on 2011-02-28
8
581 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
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 
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 500 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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 …
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

688 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