DataTable, BindingSource and DataGridView

DataTable, BindingSource and DataGridView

Anonymous
Not applicable
1,528 Views
2 Replies
Message 1 of 3

DataTable, BindingSource and DataGridView

Anonymous
Not applicable

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 DataGridView, but I don't manage to connect/set it to the DataSet.

 

I've tried to Add, clone, New Object and loop through to set det values, but probably with some errors. 

Below is the main load/open code. Here without the Dataset; data_vault.Revenue.

 


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)));


//Splitting the textfile
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;

 

//Inserting values in the table
for(int j = 0; j < (count-1)/2;j++)
{
DataRow RowValues = dtable.NewRow();

RowValues[0] = Convert.ToDouble(s_list[i]);
i++;
RowValues[1] = Convert.ToDouble(s_list[i]);
i++;

dtable.Rows.Add(RowValues);
}

dataGridView1.DataSource = dtable;
}

 

 

 

 

Later I'm collecting the values;

foreach (var obj in data_vault.Revenue)
{
double l2_tall = (Double)dataGridView1["l2nDataGridViewTextBoxColumn", i].Value;
l2_test.Add(l2_tall);


double l1_tall = (Double)dataGridView1["l1nDataGridViewTextBoxColumn", i].Value;
l1_test.Add(l1_tall);

i++;
}

0 Likes
Accepted solutions (1)
1,529 Views
2 Replies
Replies (2)
Message 2 of 3

jeremytammik
Autodesk
Autodesk
Accepted solution

I assume this has nothing whatsoever to do with the Revit API per se?

 

You might be better served discussing it in a dedicated .NET forum, or a generic Internet search, or StackOverflow, e.g.:

 

https://duckduckgo.com/?q=edit+dataset+datagridview

 

 

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 3

Anonymous
Not applicable

You are correct, sir.
I'll try that than, whatsoever you say 😉

0 Likes