c# - How to disable (read only)a cell in a DataGridView CheckBox column based on the value in other cells? -


i found many similar questions , answers none me solve issue.

please find datagridview below,

enter image description here

what want disable check box if name cell empty @ run time.

i tried may methods, time cell disabled(read only) after checked it.

edit

i tried this,

private void senddgv_cellcontentclick(object sender, datagridviewcelleventargs e)     {         if (senddgv.currentrow.cells[1].value != null)         {             senddgv.currentrow.cells[2].readonly = false;             senddgv.update();         }         else          {             senddgv.currentrow.cells[2].readonly = true;             senddgv.update();         } } 

to handle changes in column name, can use datagridview.cellvaluechanged event. e parameter give access to:

  • columnindex property, can test if change made on name column (index 1).
  • rowindexproperty, retrieve concerned row , change values want.

private void datagridview1_cellvaluechanged(object sender, system.windows.forms.datagridviewcelleventargs e) {     //second column     if (e.columnindex == 1) {         object value = datagridview1.rows[e.rowindex].cells[e.columnindex].value;         if (value != null && value.tostring() != string.empty) {             datagridview1.rows[e.rowindex].cells[2].readonly = false;         } else {             datagridview1.rows[e.rowindex].cells[2].readonly = true;         }     } } 

edit

as else noticed, in order have checkbox disabled new rows added (especially if allowusertoaddrow property set true), can handle rowadded event:

private void datagridview1_rowsadded(object sender, datagridviewrowsaddedeventargs e) {     datagridview1.rows[e.rowindex].cells[2].readonly = true; } 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -