Click here to Skip to main content
15,890,690 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all! I have a question. Please help me.
I have a datagridview which display data from many users.
Now, i want to permission to edit data from that datagridview.
Admin account can edit all data.
User account couldn't edit data rows of other user.

Example: Row1: Username1 recorded datarow1
Rows: Username2 recorded datarow2.
Username1 couldn't edit datarow2, and username2 couldn't edit datarow1
Admin can edit any datarow.

Please help me code from event get username from Login successful and put into datagridview to permission editing.
Thanks very much!

What I have tried:

I don't know how to link username to datagridview.
Posted
Updated 17-Nov-17 14:12pm
Comments
Sinisa Hajnal 11-Nov-17 15:34pm    
Put current user name into the session and compare on row binding. Add role checking and you're done. Admin will have right regardless of the user name and particular user will get his edit on his own rows.
Karthik_Mahalingam 11-Nov-17 20:24pm    
I guess it's Windows app since OP has mentioned "datagridview"

try something like this
string userName = GetCurrentUser();
           string role = GetRole(userName);

           if(role != "Admin")
           for (int i = 0; i < dataGridView1.Rows.Count; i++)
           {
               if ((dataGridView1.Rows[i].Cells["UserName"].Value != userName))
               {
                   dataGridView1.Rows[i].ReadOnly = true;
               }
           }

refer DataGridViewRow.ReadOnly Property (System.Windows.Forms)[^]
 
Share this answer
 
Thanks for you supporting. I had try and success...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900