Hi,
I made a DataSet, and bounded (DataSource/BindningSource) it to a DataGridView.
From here the user can type in (double) values which I can later use for my calculations.
I've added a button for saving and loading the tables. When i Load/Opens a table the values are displaying in the Form-DataGridView, but I don't manage to connect/set it to the DataSet.
Below is the main load/open code. Here without the Dataset; data_vault.Revenue.
private void Open_Click(object sender, EventArgs e)
{
OpenFileDialog open_data = new OpenFileDialog();
open_data.Title = "Open file";
open_data.Filter = "XML Files (*.xml)|*.xml";
if (open_data.ShowDialog() == DialogResult.OK)
{
StreamReader read_table = new StreamReader(File.OpenRead(open_data.FileName));
DataTable dtable = new DataTable();
dtable.Columns.Add(new DataColumn("L2_n", typeof(double)));
dtable.Columns.Add(new DataColumn("L1_n", typeof(double)));
List<string> s_list = new List<string>();
string str = read_table.ReadLine();
char[] spearator = { '.', ' ' };
String[] strlist = str.Split(spearator);
foreach (String s in strlist)
{
s_list.Add(s);
}
int count = s_list.Count;
int i = 0;
for (int j = 0; j < (count - 1) / 2; j++)
{
DataRow RowValues = dtable.NewRow();
double d = Double.Parse(s_list[i]);
RowValues[0] = Double.Parse(s_list[i]);
i++;
RowValues[1] = Double.Parse(s_list[i]);
i++;
dtable.Rows.Add(RowValues);
}
dataGridView1.DataSource = dtable;
}
}
Later I'm collecting the values;
private void button1_Click(object sender, EventArgs e)
{
int i = 0;
foreach (var obj in data_vault.Revenue)
{
double l2_tall = (Double)dataGridView1["l2nDataGridViewTextBoxColumn", i].Value;
double l1_tall = (Double)dataGridView1["l1nDataGridViewTextBoxColumn", i].Value;
i++;
}
Line straight_line = Line.CreateBound(l2_tall , l1_tall);
}
What I have tried:
I've tried to Add, clone, New Object and loop through to set det values. Also
OleDbDataAdapter -> adapter.Update(dtable);
and SQL
..but probably with some errors.