Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have DataGridView in my form.
C#
private void BAddStepLimit_Click(object sender, EventArgs e)
        {
            steplimitdr = spq.steplimitdt.NewRow();
            steplimitdr["stepnumberstlt"] = stepnum;
            steplimitdr["numberstlt"] = dataGridView3.RowCount + 1;
            steplimitdr["normname"] = LNormNameStLt.Text;
            steplimitdr["highwarning"] = NHighWarning.Value;
            steplimitdr["highshutdown"] = NHighshutDown.Value;
            steplimitdr["lowwarning"] = NLowWarning.Value;
            steplimitdr["lowshutdown"] = NLowShutDown.Value;
            steplimitdr["limitholdtime"] = NLimitholdTime.Value;
            if (CBUpperReact.SelectedIndex > -1)
            {
                steplimitdr["upperreact"] = CBUpperReact.Items[CBUpperReact.SelectedIndex];
            }
            if(CBLowerReact.SelectedIndex>-1)
            {
            steplimitdr["lowerreact"] = CBLowerReact.Items[CBLowerReact.SelectedIndex];
            }
            spq.steplimitdt.Rows.Add(steplimitdr);
            bindingSource2.DataSource = spq.steplimitdt;
            dataGridView4.DataSource = bindingSource2.DataSource;
            
        }

and i saved it to my xmltextwriter
the code:
C#
DataTable dt = sq.stepdt;
                        
                        for (int i = 0; i <= dt.Rows.Count-1; i++)
                        {
                            writer.WriteStartElement("Record1");
                            
                            writer.WriteAttributeString("number", tablestep.Rows[i].Cells[0].Value.ToString());
                            writer.WriteAttributeString("stepnumstep", tablestep.Rows[i].Cells[1].Value.ToString());
                            writer.WriteAttributeString("name", tablestep.Rows[i].Cells[2].Value.ToString());
                            writer.WriteAttributeString("description", tablestep.Rows[i].Cells[3].Value.ToString());
                            writer.WriteAttributeString("condition", tablestep.Rows[i].Cells[4].Value.ToString());
                            writer.WriteAttributeString("loopcount", tablestep.Rows[i].Cells[5].Value.ToString());
                            writer.WriteAttributeString("recorder", tablestep.Rows[i].Cells[6].Value.ToString());
                            writer.WriteAttributeString("dyabbreviation", tablestep.Rows[i].Cells[7].Value.ToString());
                            writer.WriteAttributeString("dydynovalue", tablestep.Rows[i].Cells[8].Value.ToString());
                            writer.WriteAttributeString("dyramp", tablestep.Rows[i].Cells[9].Value.ToString());
                            writer.WriteAttributeString("enabbreviation", tablestep.Rows[i].Cells[10].Value.ToString());
                            writer.WriteAttributeString("enenginevalue", tablestep.Rows[i].Cells[11].Value.ToString());
                            writer.WriteAttributeString("enramp", tablestep.Rows[i].Cells[12].Value.ToString());
                            writer.WriteAttributeString("max", tablestep.Rows[i].Cells[13].Value.ToString());
                            writer.WriteAttributeString("holdtime", tablestep.Rows[i].Cells[14].Value.ToString());
                            writer.WriteAttributeString("sample", tablestep.Rows[i].Cells[15].Value.ToString());
                            writer.WriteAttributeString("steptime", tablestep.Rows[i].Cells[16].Value.ToString());
                            writer.WriteEndElement();
                        }
but dont work.
help me,please.
Posted
Updated 23-Nov-11 11:27am
v2

1 solution

Don't store or load any controls to/from XML. Instead, have a data layer which you can persist in XML. You can bind a data layer with you control(s) or "manually" develop methods to populate/update your UI and update data layer based on the changes/events in UI.

You don't need to persist you data in XML using low-level XML classes. You can do it automatically using Data Contracts, see http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].

See also my past solutions:
How can I utilize XML File streamwriter and reader in my form application?[^],
Creating property files...[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900