本文介绍了将DataGridView中的数据保存到XmlTextwriter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的表单中有DataGridView.
I have DataGridView in my form.
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;
}
然后将其保存到我的xmltextwriter
代码:
and i saved it to my xmltextwriter
the code:
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.
推荐答案
这篇关于将DataGridView中的数据保存到XmlTextwriter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!