0

i have a datagridview with some rows that have edit and delete buttons,if user click on the edit button then i want to disable all the edit and delete buttons of all rows, i use ReadOnly properties in 2 ways but it doesn't help and the buttons are still clickable, there is my code, can anyone help? tnx.

foreach(DataGridViewRow row in grdWorkDayTime.Rows)
            {
                DataGridViewButtonCell btncell = (DataGridViewButtonCell)row.Cells[4]; //Cells[4] is edit button
                btncell.ReadOnly = true;
                row.Cells[5].ReadOnly = true; //Cells[5] is delete button
            }
  • 2
    Possible duplicate of [Disabling the button column in the datagridview](https://stackoverflow.com/questions/12525305/disabling-the-button-column-in-the-datagridview) – opewix Jan 19 '19 at 09:46
  • @opewix hi. i write this code at the end of function there is nothing after this to change it again, and i use `ReadOnly` properties just in this code ,nowhere else. idon't know what is wrong – mohamd J.A. Jan 19 '19 at 10:13
  • You can try to follow official Microsoft guide https://learn.microsoft.com/en-us/dotnet/framework/winforms/controls/disable-buttons-in-a-button-column-in-the-datagrid – opewix Jan 19 '19 at 10:30
  • @opewix i do what they say in that article and the color of my buttons looks like they are disable but when i click on them they work, they are still clickable, not completely disable. why they don't create a simple way to disable the buttons we are in 21st century :| – mohamd J.A. Jan 19 '19 at 13:26
  • It is unclear “why” this requirement is needed. “Usually” if the rows in the grid have an “Edit” button column, then this is (usually) because there is more data than is displayed in the grid, or there is a lot of data (columns) in the row and not all data is displayed in the grid view. In either case, this “usually” would involve opening another window/form to allow the user to “edit” the “entire” row or “edit” data that may not be displayed in the grid. If this window/form is open with a “ShowDialog”, then the user would not be able to do “anything” outside of the “Edit” form. – JohnG Jan 20 '19 at 04:42
  • What is supposed to happen when the user presses the “edit” button? Does another form open? – JohnG Jan 20 '19 at 04:42
  • @JohnG no, some informations show up in text boxes then user can edit them and at the end click on submit changes...i fix it but not with ReadOnly properties , ReadOnly properties still doesn't work for me – mohamd J.A. Jan 22 '19 at 17:42
  • @JohnG the way that you say (open new form) is good tnx man – mohamd J.A. Jan 22 '19 at 18:57

0 Answers0