You can
Convert XML to strongly typed class via image below then load and place into a list. See the following code sample where the Model folder contains classes for the XML and Classes folder to deserialize XML.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello
Is there any good way to get values which are displayed in a DataGridView as strings and take them convert them to decimals and than show into a chart?
I actually do not know where to start to solve this. I'm able to display the data into a DataGridView. I also know that these are all string so before to display anything I would guess that I need to convert the data into decimals (in my case decimals but it needs to be at least a number and not a string).
So my form_Load method has this code:
private void frmHistoricalChart_Load(object sender, EventArgs e)
{
//Set up DayaGridView style
dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.LightGray;
dataGridView1.EnableHeadersVisualStyles = false;
dataGridView1.ColumnHeadersDefaultCellStyle.Font = new Font("ABBvoice", 9, FontStyle.Bold);
dataGridView1.RowsDefaultCellStyle.Font = new Font("ABBvoice", 8);
dataGridView1.AllowUserToAddRows = false;
//Deserialize
_root = HelperXml.DeserializeXMLFileToObject<XmlRoot>(frmMain.ClientFileName);
statusLblCompany.ForeColor = Color.Black;
statusLblCompany.Text = "Company Name: " + _root.CompanyProfile.CompanyName;
statusLblSitename.Text = "Sitename: " + _root.CompanyProfile.SiteName;
statusLblMachineTotal.Text = "Machine Total: " + _root.CompanyProfile.MachineTotal.ToString();
//Bind the Machine Profile to a datasource
BindingSourceMachineProfiles.DataSource = _root.MachineProfiles.ToList();
cmbMachineName.DataSource = BindingSourceMachineProfiles;
//Bind the Machine Names
BindingSourceMachineNames.DataSource = _root.MachineProfiles.ToList().Select(i => i.MachineName);
//Bind the Machine Measurements
BindingSourceMachineMeasurements.DataSource = _root.MachineProfiles.Where(i => i.MachineName == cmbMachineName.SelectedItem.ToString()).Select(i => i.MachineMeasurements).First();
dataGridView1.DataSource = BindingSourceMachineMeasurements;
}
It loads data from a XML file and by selecting an item at the combobox I'm able to decide which data should be visible on the DataGridView. I think that is not the point. I need to be able to show for example the data (in decimals) from the first column and the second column. But before I can send this to a chart object I think I need to convert them.
How can I do this the best way?
You can
Convert XML to strongly typed class via image below then load and place into a list. See the following code sample where the Model folder contains classes for the XML and Classes folder to deserialize XML.
Hello,
First of all my apologies I thought I had given information that I was able to resolve this. At the moment I'm at a offshore platform with limited internet. But I "solved" my issue as follows:
yHDE = Convert.ToDouble(row.Cells[2].Value, CultureInfo.InvariantCulture);