It is written in the question that the data is displayed in
DataGridView
. But I think this statement
List<tuple><bool,>> list = new List<tuple><bool,>>();
may not be compiled, as no type argument is provided after ,.
Tuple
is provided to create a data structure with required number of members. This is an immutable type, which means after creation of the
Tuple
it's member values cannot be changed. Hence,
Tuple
is not suitable for the above purpose.
For displaying the data, editing the data and saving the data to DB, a database is required. MS SQL Server, MS Access etc. can be used, for which first a database has to be created and the corresponding
DataSet
and
DataTables
are to be created in
ADO.NET
. There are other options available like Entity FrameWork, XML etc.
For this purpose I made a code sample using a
DataTable
which can be saved to an
XML
file and the data saved to the xml file can be read into the
DataTable
using the save and open buttons, as shown below
DataTable dataTable1 = new DataTable();
dataTable1.TableName = "NameStatus";
dataTable1.Columns.Add("Status", typeof(bool), null);
dataTable1.Columns.Add("Name", typeof(string), null);
dataTable1.Rows.Add(true, "IPS");
dataTable1.Rows.Add(false, "IAS");
dataTable1.Rows.Add(true, "IRS");
DataGridView dataGridView1 = new DataGridView();
dataGridView1.DataSource = dataTable1;
dataGridView1.Dock = DockStyle.Fill;
Controls.Add(dataGridView1);
Button openButton = new Button();
openButton.Dock = DockStyle.Bottom;
openButton.Text = "Open";
Controls.Add(openButton);
openButton.Click += (s, args) => {
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "XML file | *.xml";
openFileDialog.ShowDialog();
dataTable1.Clear();
dataTable1.ReadXml(openFileDialog.FileName);
openFileDialog.Dispose();
};
Button saveButton = new Button();
saveButton.Dock = DockStyle.Bottom;
saveButton.Text = "Save";
Controls.Add(saveButton);
saveButton.Click += (s, args) => {
SaveFileDialog saveFileDailog = new SaveFileDialog();
saveFileDailog.Filter = "XML file | *.xml";
saveFileDailog.ShowDialog();
dataTable1.WriteXml(saveFileDailog.FileName);
saveFileDailog.Dispose();
};
To run the above sample, create
Windows Forms application
double click on
Form1
in the designer to create method body for the the
Load
event of
Form1
, paste above code in the
Form1_Load
method and run the application.