Hi
Using c# I need to save my datagrid(WPF) directly into a binary file(Bxaml) and read it back
later into the datagrid. Here is my old win forms datagridview Is it possible to convert this?
I have using System IO in the form
string file = @"c:\ps1\database.bin";
using (BinaryWriter bw = new BinaryWriter(File.Open(file, FileMode.Create))) // open or create file
{
bw.Write(DataGridView.Columns.Count); //count columns (starts at 0) and write info to file
bw.Write(DataGridView.Rows.Count); // count rows (starts at zero) and write info to file
foreach (DataGridViewRow dgvR in DataGridView.Rows) // repeat for every line inc last line for new
{
for (int j = 0; j < DataGridView.Columns.Count; ++j) // read columns data in order in order
{
object val = dgvR.Cells[j].Value; // change cell content to object
if (val == null) // if nothing in cell it will be blank
{
bw.Write(false);// allows for blank cell
bw.Write(false); // allows for null string
}
else
{
bw.Write(true); // get binary content for cell
bw.Write(val.ToString()); // change content to string and write it to file
}
}
}
Thank You in anticipation of a reply
Joe King