c# - The program hangs when I try to replace image? -
i have following code:
private void datagridview1_cellformatting(object sender, datagridviewcellformattingeventargs e) { datagridview dgv = sender datagridview; if (dgv.columns[e.columnindex].name.equals("edit")) { string status = datagridview1.rows[e.rowindex].cells["status"].value.tostring(); if (status == "1") { dgv.rows[e.rowindex].cells["edit"].value = properties.resources.edit_disable; } } }
when try replace image here:
dgv.rows[e.rowindex].cells["edit"].value = properties.resources.edit_disable;
program hangs , image , rendered infinity
you selected wrong event changing image. event datagridview1_cellformatting
fired when image changes, if use event change image, getting infinite loop.
since code querying cell's value
, might want switch different event, fired when row / cell data changes or binds, such datagridview.databindingcomplete
or datagridview1.rowsadded
:
private void datagridview1_rowsadded(object sender, datagridviewrowsaddedeventargs e) { string status = datagridview1.rows[e.rowindex].cells["status"].value.tostring(); if (status == "1") { dgv.rows[e.rowindex].cells["edit"].value = properties.resources.edit_disable; } }
Comments
Post a Comment