Good Evening.I have q question to you.Maybe you can help me.How can I load a Data from XML file to DataGridView like the table below:y\x [0,0] 0.000976563 0.000976563 0.000976563 0.000976563 0.000976563y\x [10,10] 0.000976563 0.000976563 0.000976563 0.000976563 0.000976563y\x [20,20] 0.000976563 0.000976563 0.000976563 0.000976563 0.000976563y\x [30,30] 0.000976563 0.000976563 0.000976563 0.000976563 0.000976563y\x [40,40] 0.000976563 0.000976563 0.000976563 0.000976563 0.000976563The structure of my XML file is:
I Have tried the next code, but it does not work: Parameter1 7 2 0;2;8;12;14;16;19; -20;-10; 0000000000000;5.0000000000000000;10.0000000000000000;15.0000000000000000;20.0000000000000000;25.0000000000000000;0000000000000;5.0000000000000000;10.0000000000000000;15.0000000000000000;20.0000000000000000;25.0000000000000000; Parameter2 7 3 0;2;4;6;8;10;12; 20;40;60; 0000000000000;5.0000000000000000;10.0000000000000000;15.0000000000000000;20.0000000000000000;30.0000000000000000; 0000000000000;5.0000000000000000;10.0000000000000000;15.0000000000000000;20.0000000000000000;30.0000000000000000;0000000000000;5.0000000000000000;10.0000000000000000;15.0000000000000000;20.0000000000000000;30.0000000000000000; XDocument xmlDoc = XDocument.Load("C:\\Write.xml");var variables = from variable in xmlDoc.Descendants("Parameter")where variable.Element("Name").Value == "Parameter1"select new {Name = variable.Element("Name").Value,SizeX = variable.Element("Size_X").Value,SizeY = variable.Element("Size_Y").Value,ValueX = variable.Element("Value_X").Value,ValueY = variable.Element("Value_Y").Value,Value = variable.Element("Value").Value,}; foreach (var variable in variables){ var x = Convert.ToInt32(variable.SizeX);var y = Convert.ToInt32(variable.SizeY);dataGridView1.TopLeftHeaderCell.Value = "y/x";var arr = new double[y, x];//{Value} it must be the value here???var columnCount = arr.GetUpperBound(1) + 1;var rowCount = arr.GetUpperBound(0) + 1;for (int i = 0; i < columnCount; i++){ dataGridView1.Columns.Add(i.ToString(), variable.ValueX);}for (int i = 0; i < rowCount; i++){ dataGridView1.Rows.Add(i.ToString(),variable.ValueY);for (int k = 0; k < columnCount; k++){ dataGridView1.Rows[i].Cells[k].Value = arr[i, k];}}Thanks a lot for your Answer.Best Regards,Malush
Replies
Know the answer? Post it — somebody with the same question will find it here.