c# - Write to Custom Binary File from DataGridView -
first of all, i'm loading large file data grid view (~100mb). file contains dozens of "profiles". user able select profile want view after gets loaded data grid view. want enable user select specific profile , have them save individual file don't have open large file every time. here how file loaded (note it's databound data grid view):
private void boardlistview_selectionchanged(object sender, eventargs e) { if (boardlistview.selectedrows.count > 0) { var s = (boardcandidateoffset)boardlistview.selectedrows[0].databounditem; loadfromfile(s); plotmodel.resetallaxes(); plotview.invalidateplot(true); } }
and here read file:
private void loadfromfile(boardcandidateoffset b) { profiles.clear(); using (var stream = file.openread(currentfilename)) using (var reader = new binaryreader(stream)) { stream.seek(b.fileoffset, seekorigin.begin); (int = 0; < b.count; i++) { profiles.add(custprofilelist.readfrombinaryreader(reader)); } } }
and here attempt write selected profile new file:
private void saveastoolstripmenuitem_click(object sender, eventargs e) { if (boardlistview.rows.count > 0) { savefiledialog saveboard = new savefiledialog(); saveboard.defaultext = ".prof"; if (saveboard.showdialog() == dialogresult.ok) { using (stream stream = file.create(saveboard.filename)) { using (var writer = new binarywriter(stream)) { foreach(var p in profiles) { p.writetobinarywriter(writer); } } } } } else return; }
unfortunately though, i'm getting nothing in file create. suggestions?
Comments
Post a Comment