0
I have a little problem because I am reading the tags of an xml of Nfe, but I am not able to show in the columns of datagridview, my code is reading the correct tags, but do not notice anything in datagridview.
follows the xml part I’m reading
-<det nItem="1">
-<prod>
<cProd>PA3003</cProd>
<cEAN/>
<xProd>OLEO ESSENCIAL DE CITRONELA</xProd>
<NCM>33012911</NCM>
<CEST>2000600</CEST>
<EXTIPI>00</EXTIPI>
<CFOP>5101</CFOP>
<uCom>KG</uCom>
<qCom>25.0000</qCom>
<vUnCom>123.900000000</vUnCom>
<vProd>3097.50</vProd>
<cEANTrib/>
<uTrib>KG</uTrib>
<qTrib>25.0000</qTrib>
<vUnTrib>123.900000000</vUnTrib>
<indTot>1</indTot>
<xPed>002497/1</xPed>
</prod>
follows my code
private void btn_xml_Click(object sender, EventArgs e)
{
string FileName = @"C:\Xml_Entrada\2053- CITROLEO.xml";
List<string> ListaItens = new List<string>();
XmlDocument doc = new XmlDocument();
doc.Load(FileName);
var proditens = doc.GetElementsByTagName("prod");
foreach (XmlElement nodo in proditens)
{
ListaItens.Add(nodo.GetElementsByTagName("cProd")[0].InnerText.Trim());
ListaItens.Add(nodo.GetElementsByTagName("xProd")[0].InnerText.Trim());
ListaItens.Add(nodo.GetElementsByTagName("qCom")[0].InnerText.Trim());
}
dgw_Xml.DataSource = ListaItens;
}
class ClasseItensXml
{
string CodigoProduto;
string NomeProduto;
string QtdProduto;
public string CodigoP
{
get { return CodigoProduto; }
set { CodigoProduto = value; }
}
public string NomeP
{
get { return NomeProduto; }
set { NomeProduto = value; }
}
public string QtdP
{
get { return QtdProduto; }
set { QtdProduto = value; }
}
}
you’re putting in the
ListaItens
and putting as source theproditens
...– Rovann Linhalis
So Rovann thanks for the attention, but when I put the Item Listings, I only see a column in the datagridview with the size of the xml tags as shown below
– Junior Guerreiro
You have to edit your question, not publish as an answer. Datagridview expects to receive rows and columns to display the data, you have to provide them in this format. Add the code of the class you want to display (I imagine it is
ListaItens
) that we can demonstrate how to do.– Rovann Linhalis
If you can show me how to do thank you.
– Junior Guerreiro