c# - Updating DataGrid after deleting files -
i have wpf application shows , deletes subfiles in gridview after selecting folder folderbrowserdialog()
. have datatable , filler()
function display subfiles in datagrid. when user clicks button, files deleted. problem is, when delete files, datagrid not refresh. tried datagrid1.items.refresh();
dont know put it, did not worked. in winforms same code, did not encounter problem.here filler()
function:
private void filler() { string[] files = directory.getfiles(@pathbox.text); table = new datatable(); datagrid1.datacontext = null; (int = 0; < files.length; i++) { if (i == 0) { table.columns.add("name"); table.columns.add("type"); table.columns.add("size"); } fileinfo information = new fileinfo(files[i]); filesysteminfo systeminformation = new fileinfo(files[i]); row = table.newrow(); row["name"] = systeminformation.name; row["type"] = systeminformation.extension; row["size"] = (information.length / 1024).tostring(); table.rows.add(row); } if (table.rows.count > 0) { datagrid1.itemssource = table.defaultview; } }
and delete part:
foreach (string file in files) { fileinfo tobedeleted = new fileinfo(file); if (tobedeleted.creationtime < datetime.now.addmilliseconds(-dayvalue)) tobedeleted.delete(); }
thanks suggestions.
when deleting file, have remove row datatable also. in other way, have regenerate itemsource calling filter method. (but cost performance)
Comments
Post a Comment