Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Help with csv and listview



Permlink Replies: 46 - Last Post: Jul 6, 2017 9:28 AM Last Post By: Antonio Estevez Threads: [ Previous | Next ]
Thommy Ce

Posts: 28
Registered: 6/17/17
Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 17, 2017 3:48 AM
Hello guys i have a problem, with csv and the listview.
i need or better i want my .csv into a listview, in the forum i found someone with Listbox, but with this i canot work.

[The one with the listbox|https://forums.embarcadero.com/thread.jspa?messageID=883821󗱭]

well i thought i can change Stringlist to Itemlist but it does not work.
Im missing something but i dont now what.

I can fill a second listview with a .xml waht i needed and it works great and he fills it with this code

_di_IXMLNtryDtlsType Ntrydtls = GetNtryDtls(xml_table->XMLDocument1);
xml_table ->xml_listview ->Items->Clear();
for(int i = 0; i < Ntrydtls ->Count; i++)
{

xml_table ->xml_listview->Items->Add();

xml_table ->xml_listview->Items->Item[i]->Caption = Ntrydtls->...;
xml_table ->xml_listview->Items->Item[i]->SubItems->Add()..;
xml_table ->xml_listview->Items->Item[i]->SubItems->Add...

is there a way to do the same with a .csv ?

i really need help

Edited by: Thommy Ce on May 17, 2017 3:49 AM

Edited by: Thommy Ce on May 17, 2017 4:13 AM
Asger Joergensen

Posts: 370
Registered: 11/18/08
Re: Help with csv and listview [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 17, 2017 5:58 AM   in response to: Thommy Ce in response to: Thommy Ce
Hi Thommy

You mention listview, Listbox, Stringlist and Itemlist, so I'm a little unclear
as to what you want so I go with: "i want my .csv into a listview"

a csv file is ordered
col, col, col, col \r\n
col, col, col, col \r\n
etc.

so you can read your file into a TStringlist::LoadFromFile, this give you
a row on each line, each of these line should be ordered as above as CommaText

The ListView unfortunately have a Caption as the first col, so you will have to
use an extra TStringList as a line / row parser

something like this (not testet):
void parseCsv( String file, TListItems* items)
{
   std::auto_ptr<TStringList> lstPtr( new TStringList() );
   TStringList* Lst = lstPtr.get();
   std::auto_ptr<TStringList> rowPtr( new TStringList() );
   TStringList* Row = rowPtr.get();
 
 
   Lst->LoadFromFile( file );
   int C = Lst->Count;
   for( int i = 0; i < C; ++i )
   {
      Row->CommaText = Lst->Strings[i];
      int rC = Row->Count;
 
      if( rC < 1 )continue;
 
      TListItem* newItem = items->Add();
      newItem->Caption = Row->Strings[0];
      for( int i = 1; i < rC; ++i )
      {
         newItem->SubItems->Add( Row->Strings[i] );
      }
   }
}


Best regards
Asger
Thommy Ce

Posts: 28
Registered: 6/17/17
Re: Help with csv and listview [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 17, 2017 7:09 AM   in response to: Asger Joergensen in response to: Asger Joergensen
well sry i'm a bit nervous because i need this project done, and im searching like.... for a solution.

one solution was , like in the other post csv loadfile into a listbox.

but i dont like listbox and my xml working with listview too.

so i just thought there must be an easy way like the one with listbox, to import my csv file into an listview.

i will try your example a bit maybe i will get. but i hope u now understand my problem better ?

or in an easy way, if u forgett about al i said
i need to import a csv into a Listview in c++ builder

thanks for the reply and for your help :)
Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: Help with csv and listview [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 17, 2017 8:53 AM   in response to: Thommy Ce in response to: Thommy Ce
El 17/05/2017 a las 16:09, Thommy Ce escribió:
well sry i'm a bit nervous because i need this project done, and im searching like.... for a solution.

one solution was , like in the other post csv loadfile into a listbox.

but i dont like listbox and my xml working with listview too.

so i just thought there must be an easy way like the one with listbox, to import my csv file into an listview.

i will try your example a bit maybe i will get. but i hope u now understand my problem better ?

or in an easy way, if u forgett about al i said
i need to import a csv into a Listview in c++ builder

thanks for the reply and for your help :)

Try this:

void __fastcall LoadCsvInToListView(TListView *ListView, String FileName)
{
    TStringList *CsvFile= new TStringList();
    try
    {
       CsvFile->LoadFromFile(FileName);
 
       TStringList *CsvRow= new TStringList();
       try
       {
          CsvRow->Delimiter= ';';
          CsvRow->QuoteChar= '"';
          CsvRow->StrictDelimiter= true;
 
          for (int Row= 0; Row< CsvFile->Count; ++Row)
          {
             CsvRow->DelimitedText= CsvFile->Strings[Row];
 
             TListItem *Item= ListView->Items->Add();
             Item->Caption= CsvRow->Strings[0];
             for (int Col= 1; Col< CsvRow->Count; ++Col)
                Item->SubItems->Add(CsvRow->Strings[Col]);
          }
       }
       __finally
       {
          delete CsvRow;
       }
    }
    __finally
    {
       delete CsvFile;
    }
}
Thommy Ce

Posts: 28
Registered: 6/17/17
Re: Help with csv and listview [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 18, 2017 3:14 AM   in response to: Antonio Estevez in response to: Antonio Estevez
Antonio Estevez wrote:
El 17/05/2017 a las 16:09, Thommy Ce escribió:
well sry i'm a bit nervous because i need this project done, and im searching like.... for a solution.

one solution was , like in the other post csv loadfile into a listbox.

but i dont like listbox and my xml working with listview too.

so i just thought there must be an easy way like the one with listbox, to import my csv file into an listview.

i will try your example a bit maybe i will get. but i hope u now understand my problem better ?

or in an easy way, if u forgett about al i said
i need to import a csv into a Listview in c++ builder

thanks for the reply and for your help :)

Try this:

void __fastcall LoadCsvInToListView(TListView *ListView, String FileName)
{
    TStringList *CsvFile= new TStringList();
    try
    {
       CsvFile->LoadFromFile(FileName);
 
       TStringList *CsvRow= new TStringList();
       try
       {
          CsvRow->Delimiter= ';';
          CsvRow->QuoteChar= '"';
          CsvRow->StrictDelimiter= true;
 
          for (int Row= 0; Row< CsvFile->Count; ++Row)
          {
             CsvRow->DelimitedText= CsvFile->Strings[Row];
 
             TListItem *Item= ListView->Items->Add();
             Item->Caption= CsvRow->Strings[0];
             for (int Col= 1; Col< CsvRow->Count; ++Col)
                Item->SubItems->Add(CsvRow->Strings[Col]);
          }
       }
       __finally
       {
          delete CsvRow;
       }
    }
    __finally
    {
       delete CsvFile;
    }
}


Thank you soo much !!!! this works for me how i need it !!! awesome, i would never get it,
And how do i solve the problem if i have more Columns like Name, second name, age etc.
with more subitems ?

best regards :)

Edited by: Thommy Ce on May 18, 2017 3:18 AM

Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 18, 2017 4:10 AM   in response to: Thommy Ce in response to: Thommy Ce
El 18/05/2017 a las 12:20, Thommy Ce escribió:
And how do i solve the problem if i have more Columns like Name, second name, age etc.
with more subitems ?

best regards :)

The function already handles that with this loop:

              for (int Col= 1; Col< CsvRow->Count; ++Col)
                 Item->SubItems->Add(CsvRow->Strings[Col]);
 


If what you meant is how to add columns to the ListView then you must do
the following:

Select the ListView component from the form designer.
In the "Object Inspector" set the ViewStyle property to vsReport.
Click over the "Columns" property and press the [...] button to open the
ListView columns editor.
Press the "Add new" button repeatedly to add all the columns you need.
Click over each column and set their properties Caption and Width
in the "Object Inspector".
Thommy Ce

Posts: 28
Registered: 6/17/17
Re: Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 18, 2017 5:37 AM   in response to: Antonio Estevez in response to: Antonio Estevez
Antonio Estevez wrote:
El 18/05/2017 a las 12:20, Thommy Ce escribió:
And how do i solve the problem if i have more Columns like Name, second name, age etc.
with more subitems ?

best regards :)

The function already handles that with this loop:

              for (int Col= 1; Col< CsvRow->Count; ++Col)
                 Item->SubItems->Add(CsvRow->Strings[Col]);
 


If what you meant is how to add columns to the ListView then you must do
the following:

Select the ListView component from the form designer.
In the "Object Inspector" set the ViewStyle property to vsReport.
Click over the "Columns" property and press the [...] button to open the
ListView columns editor.
Press the "Add new" button repeatedly to add all the columns you need.
Click over each column and set their properties Caption and Width
in the "Object Inspector".

Works, thanks a lot !! so i jsut need one more thing , but first i try it myself some days for learning :D
Thommy Ce

Posts: 28
Registered: 6/17/17
Re: Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 30, 2017 3:51 AM   in response to: Thommy Ce in response to: Thommy Ce
Ok, i need again help, i tryed now several things with XML. i build my own one, and i got.
But with a bigger xml, my code doesnt work.

SO i tried the code like the CSV one, this works, but he writes the whole XML in one Column, but i need all the data of the XML in seperate Columns.
also i tried with the tool plate XmlDokument, with this one i was a little bit better, but in the options there are some Columns i cant pick.

is there a way, or does someone a site / tutorial to read ?

Thanks again
Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 30, 2017 4:03 AM   in response to: Thommy Ce in response to: Thommy Ce
El 30/05/2017 a las 12:51, Thommy Ce escribió:
Ok, i need again help, i tryed now several things with XML. i build my own one, and i got.
But with a bigger xml, my code doesnt work.

Please show your code and the xml file. If the .xml is very large then
upload it to the "attachments" group and put the link here.

Thommy Ce

Posts: 28
Registered: 6/17/17
Re: Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 30, 2017 4:34 AM   in response to: Antonio Estevez in response to: Antonio Estevez
Antonio Estevez wrote:
El 30/05/2017 a las 12:51, Thommy Ce escribió:
Ok, i need again help, i tryed now several things with XML. i build my own one, and i got.
But with a bigger xml, my code doesnt work.

Please show your code and the xml file. If the .xml is very large then
upload it to the "attachments" group and put the link here.


The XML has some Privacy Terms, so i need to change some data.

first my two codes i tried with XMLDokument

_di_IXMLNtryDtlsType Ntrydtls = GetNtryDtls(xml_table->XMLDocument1);
xml_table ->xml_listview ->Items->Clear();
for(int i = 0; i < Ntrydtls ->Count; i++)
{

xml_table ->xml_listview->Items->Add();

xml_table ->xml_listview->Items->Item[i]->Caption = Ntrydtls->TxDtls[i]->Refs->EndToEndId ;
xml_table ->xml_listview->Items->Item[i]->SubItems->Add(Ntrydtls->TxDtls[i]->Refs->MndtId);
xml_table ->xml_listview->Items->Item[i]->SubItems->Add(Ntrydtls->TxDtls[i]->AmtDtls->TxAmt->Amt->Text.c_str());

}

_di_IXMLDocumentType Document = GetDocument(xml_table->XMLDocument1);
xml_table ->xml_listview ->Items->Clear();
for(int i = 0; i < Document ->Count; i++)
{
xml_table ->xml_listview->Items->Add();
// Document->BkToCstmrStmt->Stmt->Ntry->Items->NtryDtls->TxDtls->Refs->EndToEndId;

xml_table ->xml_listview->Items->Item[i]->Caption =
// xml_table ->xml_listview->Items->Item[i]->SubItems->Add(Ntrydtls->TxDtls[i]->Refs->MndtId);
//xml_table ->xml_listview->Items->Item[i]->SubItems->Add(Ntrydtls->TxDtls[i]->AmtDtls->TxAmt->Amt->Text.c_str());


}
*/

and the one with the Csv:

TStringList *XmlFile= new TStringList();
try
{
XmlFile->LoadFromFile(data_xml->Text);

TStringList *XmlRow= new TStringList();
try
{
XmlRow->Delimiter= ';';
XmlRow->QuoteChar= '"';
XmlRow->StrictDelimiter= true;

for (int Row= 0; Row< XmlFile->Count; ++Row)
{
XmlRow->DelimitedText= XmlFile->Strings[Row];

TListItem *Item= xml_table->xml_listview->Items->Add();

Item->Caption= XmlRow->Text;
for (int Col= 1; Col< XmlRow->Count; ++Col)
Item->SubItems->Add(XmlRow->Text);
}
}
__finally
{
delete XmlRow;
}
}
__finally
{
delete XmlFile;
}

and here the File i cutted it but it repeats with other data

<?xml version="1.0" encoding="UTF-8"?>

<Document>
<BkToCstmrStmt>
<GrpHdr>
<MsgId>33328000</MsgId>
<CreDtTm>2017-04-05T03:03:12.506</CreDtTm>
<MsgPgntn>
<PgNb>1</PgNb>
<LastPgInd>true</LastPgInd>
</MsgPgntn>
</GrpHdr>
<Stmt>
<Id>33328000</Id>
<ElctrncSeqNb>67</ElctrncSeqNb>
<CreDtTm>2017-04-05T03:03:12.506</CreDtTm>
<Acct>
<Id>
<IBAN>xxxxxxxxxx</IBAN>
</Id>
<Ownr>
<Nm>xxxxxxxxxx</Nm>
</Ownr>
<Svcr>
<FinInstnId>
<BIC>xxxxxx</BIC>
<Othr>
<Id>xxxxxxxx</Id>
<Issr>UmsStId</Issr>
</Othr>
</FinInstnId>
</Svcr>
</Acct>
<Bal>
<Tp>
<CdOrPrtry>
<Cd>PRCD</Cd>
</CdOrPrtry>
</Tp>
<Amt Ccy="EUR">xxxxxxxxx</Amt>
<CdtDbtInd>CRDT</CdtDbtInd>
<Dt>
<Dt>2017-04-03</Dt>
</Dt>
</Bal>
<Bal>
<Tp>
<CdOrPrtry>
<Cd>CLBD</Cd>
</CdOrPrtry>
</Tp>
<Amt Ccy="EUR">xxxxxxx</Amt>
<CdtDbtInd>CRDT</CdtDbtInd>
<Dt>
<Dt>2017-04-04</Dt>
</Dt>
</Bal>
<Ntry>
<Amt Ccy="EUR">xxxxxx</Amt>
<CdtDbtInd>CRDT</CdtDbtInd>
<Sts>BOOK</Sts>
<BookgDt>
<Dt>2017-04-04</Dt>
</BookgDt>
<ValDt>
<Dt>2017-04-04</Dt>
</ValDt>
<BkTxCd/>
<AddtlInfInd>
<MsgNmId>xxxxxxxx</MsgNmId>
<MsgId>33328000</MsgId>
</AddtlInfInd>
<NtryDtls>
<TxDtls>
<Refs/>
<BkTxCd>
<Prtry>
<Cd>NTRF+171</Cd>
<Issr>DK</Issr>
</Prtry>
</BkTxCd>
<RltdPties>
<Cdtr>
<Nm>xxxxxxxx</Nm>
</Cdtr>
<CdtrAcct>
<Id>
<IBAN>xxxxxxxxxxxx</IBAN>
</Id>
</CdtrAcct>
</RltdPties>
<RltdAgts>
<CdtrAgt>
<FinInstnId>
<BIC>xxxxxxxxx</BIC>
</FinInstnId>
</CdtrAgt>
</RltdAgts>
<RmtInf>
<Ustrd>xxxxxxxxx</Ustrd>
</RmtInf>
</TxDtls>
</NtryDtls>
</Ntry>
<Ntry>
<Amt Ccy="EUR">xxxxxxx</Amt>
<CdtDbtInd>xxxxxxxx</CdtDbtInd>
<Sts>BOOK</Sts>
<BookgDt>
<Dt>2017-04-04</Dt>
</BookgDt>
<ValDt>
<Dt>2017-04-04</Dt>
</ValDt>
<BkTxCd/>
<AddtlInfInd>
<MsgNmId>xxxxxxxxxx</MsgNmId>
<MsgId>xxxxxxxxxxx</MsgId>
</AddtlInfInd>
<NtryDtls>
<TxDtls>
<Refs/>
<BkTxCd>
<Prtry>
<Cd>NTRF+171</Cd>
<Issr>DK</Issr>
</Prtry>
</BkTxCd>
<RltdPties>
<Cdtr>
<Nm>xxxxxxxxxxxxx</Nm>
</Cdtr>
<CdtrAcct>
<Id>
<IBAN>xxxxxxxxxxxxx</IBAN>
</Id>
</CdtrAcct>
</RltdPties>
<RltdAgts>
<CdtrAgt>
<FinInstnId>
<BIC>xxxxxxxxxxx</BIC>
</FinInstnId>
</CdtrAgt>
</RltdAgts>
<RmtInf>
<Ustrd>xxxxxxxxxxxxxx</Ustrd>
</RmtInf>
</TxDtls>
</NtryDtls>
</Ntry>
<Ntry>
<Amt Ccy="EUR">xxxxxxxxxxxxxx</Amt>
<CdtDbtInd>DBIT</CdtDbtInd>
<Sts>BOOK</Sts>
<BookgDt>
<Dt>2017-04-04</Dt>
</BookgDt>
<ValDt>
<Dt>2017-04-04</Dt>
</ValDt>
<BkTxCd/>
<AmtDtls>
<InstdAmt>
<Amt Ccy="EUR">xxxxxxx</Amt>
</InstdAmt>
</AmtDtls>
<Chrgs>
<Amt Ccy="EUR">xxxxxxx</Amt>
<CdtDbtInd>DBIT</CdtDbtInd>

SLEV
</Chrgs>
<NtryDtls>
<TxDtls>
<Refs>
<EndToEndId>xxxxxxxxxxxxxxxx</EndToEndId>
<TxId>xxxxxxxx</TxId>
<MndtId>xxxxxxx</MndtId>
</Refs>
<BkTxCd>
<Prtry>
<Cd>NTRF+109</Cd>
<Issr>DK</Issr>
</Prtry>
</BkTxCd>
<RltdPties>
<Dbtr>
<Nm>xxxx</Nm>
</Dbtr>
<DbtrAcct>
<Id>
<IBAN>xxxxxx</IBAN>
</Id>
</DbtrAcct>
<Cdtr>
<Nm>xxxxxxxxxxx</Nm>
</Cdtr>
<CdtrAcct>
<Id>
<IBAN>xxxxx</IBAN>
</Id>
</CdtrAcct>
</RltdPties>
<RltdAgts>
<DbtrAgt>
<FinInstnId>

Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 30, 2017 4:56 AM   in response to: Thommy Ce in response to: Thommy Ce
El 30/05/2017 a las 13:34, Thommy Ce escribió:
The XML has some Privacy Terms, so i need to change some data.

first my two codes i tried with XMLDokument

_di_IXMLNtryDtlsType Ntrydtls = GetNtryDtls(xml_table->XMLDocument1);
xml_table ->xml_listview ->Items->Clear();
for(int i = 0; i < Ntrydtls ->Count; i++)
{

xml_table ->xml_listview->Items->Add();

xml_table ->xml_listview->Items->Item[i]->Caption = Ntrydtls->TxDtls[i]->Refs->EndToEndId ;
xml_table ->xml_listview->Items->Item[i]->SubItems->Add(Ntrydtls->TxDtls[i]->Refs->MndtId);
xml_table

You are trying to get data from the <Refs> tag but all of them are empty
in your xml file:

...
	<NtryDtls>
		<TxDtls>
			<Refs/>
			<BkTxCd>
...
Thommy Ce

Posts: 28
Registered: 6/17/17
Re: Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 30, 2017 5:02 AM   in response to: Antonio Estevez in response to: Antonio Estevez
Antonio Estevez wrote:
El 30/05/2017 a las 13:34, Thommy Ce escribió:
The XML has some Privacy Terms, so i need to change some data.

first my two codes i tried with XMLDokument

_di_IXMLNtryDtlsType Ntrydtls = GetNtryDtls(xml_table->XMLDocument1);
xml_table ->xml_listview ->Items->Clear();
for(int i = 0; i < Ntrydtls ->Count; i++)
{

xml_table ->xml_listview->Items->Add();

xml_table ->xml_listview->Items->Item[i]->Caption = Ntrydtls->TxDtls[i]->Refs->EndToEndId ;
xml_table ->xml_listview->Items->Item[i]->SubItems->Add(Ntrydtls->TxDtls[i]->Refs->MndtId);
xml_table

You are trying to get data from the <Refs> tag but all of them are empty
in your xml file:

...
	<NtryDtls>
		<TxDtls>
			<Refs/>
			<BkTxCd>
...

but a bit more down are
<Refs>
<EndToEndId>xxxxxxxxxxxxxxxx</EndToEndId>
<TxId>xxxxxxxx</TxId>
<MndtId>xxxxxxx</MndtId>
</Refs>

and this ref is what i need and here are data

i wouldnt had n problem if he fills everything like the csv file
butt i only need 3 or 4 columns from the xml but if this is a easier way ? i could live with that

Edited by: Thommy Ce on May 30, 2017 5:51 AM

Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 30, 2017 7:56 AM   in response to: Thommy Ce in response to: Thommy Ce
El 30/05/2017 a las 14:53, Thommy Ce escribió:


but a bit more down are
<Refs>
<EndToEndId>xxxxxxxxxxxxxxxx</EndToEndId>
<TxId>xxxxxxxx</TxId>
<MndtId>xxxxxxx</MndtId>
</Refs>

and this ref is what i need and here are data

i wouldnt had n problem if he fills everything like the csv file
butt i only need 3 or 4 columns from the xml but if this is a easier way ? i could live with that

Edited by: Thommy Ce on May 30, 2017 5:51 AM

If you only need the data from the <Refs> node then you can call the
following recursive function:

void __fastcall AddNodeToListView(TListView *ListView, _di_IXMLNode Node)
{
    if (Node->NodeName== L"Refs")
    {
       String EndToEndId, TxId, MndtId;
       _di_IXMLNodeList Childs= Node->ChildNodes;
 
       for (int x= 0; x< Childs->Count; ++x)
       {
          _di_IXMLNode Node= Childs->Nodes[x];
          String Name= Node->NodeName;
          if (Name== L"EndToEndId")
             EndToEndId= Node->Text;
          else if (Name== L"TxId")
             TxId= Node->Text;
          if (Name== L"MndtId")
             MndtId= Node->Text;
       }
 
       if (!EndToEndId.IsEmpty())
       {
          TListItem *Item= ListView->Items->Add();
          Item->Caption= EndToEndId;
          Item->SubItems->Add(TxId);
          Item->SubItems->Add(MndtId);
       }
    }
    else
    {
       _di_IXMLNodeList Childs= Node->ChildNodes;
       for (int i= 0; i< Childs->Count; ++i)
          AddNodeToListView(ListView, Childs->Nodes[i]);
    }
}
 
void __fastcall LoadXmlToListView(TListView *ListView, TXMLDocument *XMLDoc)
{
   ListView->Clear();
   AddNodeToListView(ListView, XMLDoc->DocumentElement);
}

You should call the LoadXmlToListView function this way

    LoadXmlToListView(xml_table->xml_listview, xml_table->XMLDocument1);
Thommy Ce

Posts: 28
Registered: 6/17/17
Re: Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 31, 2017 12:16 AM   in response to: Antonio Estevez in response to: Antonio Estevez
Antonio Estevez wrote:
El 30/05/2017 a las 14:53, Thommy Ce escribió:


but a bit more down are
<Refs>
<EndToEndId>xxxxxxxxxxxxxxxx</EndToEndId>
<TxId>xxxxxxxx</TxId>
<MndtId>xxxxxxx</MndtId>
</Refs>

and this ref is what i need and here are data

i wouldnt had n problem if he fills everything like the csv file
butt i only need 3 or 4 columns from the xml but if this is a easier way ? i could live with that

Edited by: Thommy Ce on May 30, 2017 5:51 AM

If you only need the data from the <Refs> node then you can call the
following recursive function:

void __fastcall AddNodeToListView(TListView *ListView, _di_IXMLNode Node)
{
    if (Node->NodeName== L"Refs")
    {
       String EndToEndId, TxId, MndtId;
       _di_IXMLNodeList Childs= Node->ChildNodes;
 
       for (int x= 0; x< Childs->Count; ++x)
       {
          _di_IXMLNode Node= Childs->Nodes[x];
          String Name= Node->NodeName;
          if (Name== L"EndToEndId")
             EndToEndId= Node->Text;
          else if (Name== L"TxId")
             TxId= Node->Text;
          if (Name== L"MndtId")
             MndtId= Node->Text;
       }
 
       if (!EndToEndId.IsEmpty())
       {
          TListItem *Item= ListView->Items->Add();
          Item->Caption= EndToEndId;
          Item->SubItems->Add(TxId);
          Item->SubItems->Add(MndtId);
       }
    }
    else
    {
       _di_IXMLNodeList Childs= Node->ChildNodes;
       for (int i= 0; i< Childs->Count; ++i)
          AddNodeToListView(ListView, Childs->Nodes[i]);
    }
}
 
void __fastcall LoadXmlToListView(TListView *ListView, TXMLDocument *XMLDoc)
{
   ListView->Clear();
   AddNodeToListView(ListView, XMLDoc->DocumentElement);
}

You should call the LoadXmlToListView function this way

    LoadXmlToListView(xml_table->xml_listview, xml_table->XMLDocument1);

Ty for your awesome help and your time,

but now i'm in a problem, i understand the code, but i dont get it why it dont work :/
if (Node->NodeName== L"Refs") says undefined symbol Node
if i try No and command + space i dont get a suggestion for Node just things like Node_text _document and so on
feeling rly stupid, i'm a trainee and have to learn everything by myself

Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 31, 2017 12:23 AM   in response to: Thommy Ce in response to: Thommy Ce
El 31/05/2017 a las 09:16, Thommy Ce escribió:


Ty for your awesome help and your time,

but now i'm in a problem, i understand the code, but i dont get it why it dont work :/
if (Node->NodeName== L"Refs") says undefined symbol Node
if i try No and command + space i dont get a suggestion for Node just things like Node_text _document and so on
feeling rly stupid, i'm a trainee and have to learn everything by myself

Node is the AddNodeToListView second parameter:
void __fastcall AddNodeToListView(TListView *ListView, _di_IXMLNode Node) // <------- This
{
     if (Node->NodeName== L"Refs")
     {
...
     }
}
Thommy Ce

Posts: 28
Registered: 6/17/17
Re: Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 31, 2017 12:45 AM   in response to: Antonio Estevez in response to: Antonio Estevez
Antonio Estevez wrote:
El 31/05/2017 a las 09:16, Thommy Ce escribió:


Ty for your awesome help and your time,

but now i'm in a problem, i understand the code, but i dont get it why it dont work :/
if (Node->NodeName== L"Refs") says undefined symbol Node
if i try No and command + space i dont get a suggestion for Node just things like Node_text _document and so on
feeling rly stupid, i'm a trainee and have to learn everything by myself

Node is the AddNodeToListView second parameter:
void __fastcall AddNodeToListView(TListView *ListView, _di_IXMLNode Node) // <------- This
{
     if (Node->NodeName== L"Refs")
     {
...
     }
}

Oh darn i get it now ! so i will try some things :)
TY i will report back : D , or ask a dumb question again hehe
Thommy Ce

Posts: 28
Registered: 6/17/17
Re: Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 1, 2017 1:48 AM   in response to: Antonio Estevez in response to: Antonio Estevez

You should call the LoadXmlToListView function this way
    LoadXmlToListView(xml_table->xml_listview, xml_table->XMLDocument1);

Hello Antonio, i have an problem with the call,
i want to call the LoadXmlToListView after a button click.
if i took the funktion into the button click it says its undefined.

do i need to take the funktion into the header (.h) ?
and i dont know how he could read the xml because first i open the file, and get the location into an edit. and than i read it with
xml_table->XMLDocument1->FileName = data_xml->Text;

ty for your help
Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 1, 2017 2:43 AM   in response to: Thommy Ce in response to: Thommy Ce
El 01/06/2017 a las 10:48, Thommy Ce escribió:

You should call the LoadXmlToListView function this way
     LoadXmlToListView(xml_table->xml_listview, xml_table->XMLDocument1);

Hello Antonio, i have an problem with the call,
i want to call the LoadXmlToListView after a button click.
if i took the funktion into the button click it says its undefined.

do i need to take the funktion into the header (.h) ?
and i dont know how he could read the xml because first i open the file, and get the location into an edit. and than i read it with
xml_table->XMLDocument1->FileName = data_xml->Text;

ty for your help

Please, show your actual code.
I can't help you if I don't see what you are doing.

Thommy Ce

Posts: 28
Registered: 6/17/17
Re: Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 1, 2017 2:52 AM   in response to: Antonio Estevez in response to: Antonio Estevez


Please, show your actual code.
I can't help you if I don't see what you are doing.

void __fastcall TForm1::Xml_click1Click(TObject *Sender)
{
//fill the XMLDoc with the complete path
//xml_table->XMLDocument1->FileName = data_xml->Text; <---- that was the old one

Form1 ->Visible = false;
xml_table -> Visible = true;

LoadXmlToListView(xml_table->xml_listview, xml_table->XMLDocument1);
}

and this is at the end your code, this still works ?
void __fastcall AddNodeToListView(TListView *ListView, _di_IXMLNode Node)
{
if (Node->NodeName== L"Refs")
{
String EndToEndId, TxId, MndtId;
_di_IXMLNodeList Childs= Node->ChildNodes;

for (int x= 0; x< Childs->Count; ++x)
{
_di_IXMLNode Node= Childs->Nodes[x];
String Name= Node->NodeName;
if (Name== L"EndToEndId")
EndToEndId= Node->Text;
else if (Name== L"TxId")
TxId= Node->Text;
if (Name== L"MndtId")
MndtId= Node->Text;
}

if (!EndToEndId.IsEmpty())
{
TListItem *Item= ListView->Items->Add();
Item->Caption= EndToEndId;
Item->SubItems->Add(TxId);
Item->SubItems->Add(MndtId);
}
}
else
{
_di_IXMLNodeList Childs= Node->ChildNodes;
for (int i= 0; i< Childs->Count; ++i)
AddNodeToListView(ListView, Childs->Nodes[i]);
}
}
//---------------------------------------------------------------------------
void __fastcall LoadXmlToListView(TListView *ListView, TXMLDocument *XMLDoc)
{
ListView->Clear();
AddNodeToListView(ListView, XMLDoc->DocumentElement);
}
//---------------------------------------------------------------------------

Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 1, 2017 6:16 AM   in response to: Thommy Ce in response to: Thommy Ce
El 01/06/2017 a las 11:52, Thommy Ce escribió:


Please, show your actual code.
I can't help you if I don't see what you are doing.

void __fastcall TForm1::Xml_click1Click(TObject *Sender)
{
//fill the XMLDoc with the complete path
//xml_table->XMLDocument1->FileName = data_xml->Text; <---- that was the old one

Try this:

xml_table->XMLDocument1->Active= false;
xml_table->XMLDocument1->FileName = data_xml->Text;
xml_table->XMLDocument1->Active= true;



Form1 ->Visible = false;

You should not use the global variable Form1 to access variables, properties, functions, etc. from inside a method of
its class. You should use the "this" keyword:
    this->Visible = false;


or, simply, nothing:
    Visible = false;


xml_table -> Visible = true;

LoadXmlToListView(xml_table->xml_listview, xml_table->XMLDocument1);
}

LoadXmlToListView must be declared before it's used: The compiler must know what LoadXmlToListView is.
You have many options:

A) Move both functions before the contructor body of TForm1.
//---------------------------------------------------------------------------
void __fastcall AddNodeToListView(TListView *ListView, _di_IXMLNode Node)
{
...
}
//---------------------------------------------------------------------------
void __fastcall LoadXmlToListView(TListView *ListView, TXMLDocument *XMLDoc)
{
...
}
//---------------------------------------------------------------------------
__fastcall TForm11::TForm11(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------


B) Add the declaration of the LoadXmlToListView function before it's used:
//---------------------------------------------------------------------------
void __fastcall LoadXmlToListView(TListView *ListView, TXMLDocument *XMLDoc);
//---------------------------------------------------------------------------
__fastcall TForm11::TForm11(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------


C) Add the declaration of the LoadXmlToListView function to the header file:
class TForm11 : public TForm
{
__published:	// IDE-managed Components
private:	// User declarations
public:		// User declarations
    __fastcall TForm11(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm11 *Form11;
//---------------------------------------------------------------------------
void __fastcall LoadXmlToListView(TListView *ListView, TXMLDocument *XMLDoc);
//---------------------------------------------------------------------------


D) Add the functions declaration to the TForm1 class:
class TForm11 : public TForm
{
__published:	// IDE-managed Components
private:	// User declarations
 
    void __fastcall AddNodeToListView(TListView *ListView, _di_IXMLNode Node);
    void __fastcall LoadXmlToListView(TListView *ListView, TXMLDocument *XMLDoc);
 
public:		// User declarations
    __fastcall TForm11(TComponent* Owner);
};
//---------------------------------------------------------------------------

Then you must modify the function definition as:
void __fastcall TForm1::AddNodeToListView(TListView *ListView, _di_IXMLNode Node)
{
...
}
//---------------------------------------------------------------------------
void __fastcall TForm1::LoadXmlToListView(TListView *ListView, TXMLDocument *XMLDoc)
{
...
}
Thommy Ce

Posts: 28
Registered: 6/17/17
Re: Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 1, 2017 7:03 AM   in response to: Antonio Estevez in response to: Antonio Estevez
Antonio Estevez wrote:
El 01/06/2017 a las 11:52, Thommy Ce escribió:


Please, show your actual code.
I can't help you if I don't see what you are doing.

void __fastcall TForm1::Xml_click1Click(TObject *Sender)
{
//fill the XMLDoc with the complete path
//xml_table->XMLDocument1->FileName = data_xml->Text; <---- that was the old one

Try this:

xml_table->XMLDocument1->Active= false;
xml_table->XMLDocument1->FileName = data_xml->Text;
xml_table->XMLDocument1->Active= true;



Form1 ->Visible = false;

You should not use the global variable Form1 to access variables, properties, functions, etc. from inside a method of
its class. You should use the "this" keyword:
    this->Visible = false;


or, simply, nothing:
    Visible = false;


xml_table -> Visible = true;

LoadXmlToListView(xml_table->xml_listview, xml_table->XMLDocument1);
}

LoadXmlToListView must be declared before it's used: The compiler must know what LoadXmlToListView is.
You have many options:

A) Move both functions before the contructor body of TForm1.
//---------------------------------------------------------------------------
void __fastcall AddNodeToListView(TListView *ListView, _di_IXMLNode Node)
{
...
}
//---------------------------------------------------------------------------
void __fastcall LoadXmlToListView(TListView *ListView, TXMLDocument *XMLDoc)
{
...
}
//---------------------------------------------------------------------------
__fastcall TForm11::TForm11(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------


B) Add the declaration of the LoadXmlToListView function before it's used:
//---------------------------------------------------------------------------
void __fastcall LoadXmlToListView(TListView *ListView, TXMLDocument *XMLDoc);
//---------------------------------------------------------------------------
__fastcall TForm11::TForm11(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------


C) Add the declaration of the LoadXmlToListView function to the header file:
class TForm11 : public TForm
{
__published:	// IDE-managed Components
private:	// User declarations
public:		// User declarations
    __fastcall TForm11(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm11 *Form11;
//---------------------------------------------------------------------------
void __fastcall LoadXmlToListView(TListView *ListView, TXMLDocument *XMLDoc);
//---------------------------------------------------------------------------


D) Add the functions declaration to the TForm1 class:
class TForm11 : public TForm
{
__published:	// IDE-managed Components
private:	// User declarations
 
    void __fastcall AddNodeToListView(TListView *ListView, _di_IXMLNode Node);
    void __fastcall LoadXmlToListView(TListView *ListView, TXMLDocument *XMLDoc);
 
public:		// User declarations
    __fastcall TForm11(TComponent* Owner);
};
//---------------------------------------------------------------------------

Then you must modify the function definition as:
void __fastcall TForm1::AddNodeToListView(TListView *ListView, _di_IXMLNode Node)
{
...
}
//---------------------------------------------------------------------------
void __fastcall TForm1::LoadXmlToListView(TListView *ListView, TXMLDocument *XMLDoc)
{
...
}

thank you i will try it and response you later :) thanks !
Thommy Ce

Posts: 28
Registered: 6/17/17
Re: Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 7, 2017 1:45 AM   in response to: Antonio Estevez in response to: Antonio Estevez
Antonio Estevez wrote:
El 01/06/2017 a las 11:52, Thommy Ce escribió:

LoadXmlToListView(xml_table->xml_listview, xml_table->XMLDocument1);
}

LoadXmlToListView must be declared before it's used: The compiler must know what LoadXmlToListView is.
You have many options:

A) Move both functions before the contructor body of TForm1.
//---------------------------------------------------------------------------
void __fastcall AddNodeToListView(TListView *ListView, _di_IXMLNode Node)
{
...
}
//---------------------------------------------------------------------------
void __fastcall LoadXmlToListView(TListView *ListView, TXMLDocument *XMLDoc)
{
...
}
//---------------------------------------------------------------------------
__fastcall TForm11::TForm11(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------


B) Add the declaration of the LoadXmlToListView function before it's used:
//---------------------------------------------------------------------------
void __fastcall LoadXmlToListView(TListView *ListView, TXMLDocument *XMLDoc);
//---------------------------------------------------------------------------
__fastcall TForm11::TForm11(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------


C) Add the declaration of the LoadXmlToListView function to the header file:
class TForm11 : public TForm
{
__published:	// IDE-managed Components
private:	// User declarations
public:		// User declarations
    __fastcall TForm11(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm11 *Form11;
//---------------------------------------------------------------------------
void __fastcall LoadXmlToListView(TListView *ListView, TXMLDocument *XMLDoc);
//---------------------------------------------------------------------------


D) Add the functions declaration to the TForm1 class:
class TForm11 : public TForm
{
__published:	// IDE-managed Components
private:	// User declarations
 
    void __fastcall AddNodeToListView(TListView *ListView, _di_IXMLNode Node);
    void __fastcall LoadXmlToListView(TListView *ListView, TXMLDocument *XMLDoc);
 
public:		// User declarations
    __fastcall TForm11(TComponent* Owner);
};
//---------------------------------------------------------------------------

Then you must modify the function definition as:
void __fastcall TForm1::AddNodeToListView(TListView *ListView, _di_IXMLNode Node)
{
...
}
//---------------------------------------------------------------------------
void __fastcall TForm1::LoadXmlToListView(TListView *ListView, TXMLDocument *XMLDoc)
{
...
}

Hello Antonio, well i tryied some things now, had much work and was stressed,
Now the followings on Method:

A) Worked

B) it says linking problem

C) Typename expected

D) I get Typename expected

now im fine with A he compilies it.

But my XMLDocument needs to be active, and on the XMLDocument1 i need to set the FileName,
than it works, but what we have many XML files, thats why i want to choose the XML File from my PC.
Thats why i have an OpenFile button.

i Think i need something like
LoadXmlToListView(xml_table->xml_listview, xml_table->XMLDocument1->FileName = data_xml->Text); but this dont work
so i think i need do declare the XMLDocument1 somehow , that he takes the xml from the data_xml->Text path, im right ?

so i tryied this

void __fastcall TForm1::Xml_click1Click(TObject *Sender)
{
//fill the XMLDoc with the complete path

Visible = false;
xml_table -> Visible = true;
xml_table->XMLDocument1->FileName = data_xml->Text;

LoadXmlToListView(xml_table->xml_listview, xml_table->XMLDocument1);

}

I set the XMLDocument1 active to false, that he takes the path xml not the setted xml
but if i chose the xml, he says : No active Dokument found

and jumps into: AddNodeToListView(ListView, XMLDoc->DocumentElement);

so if i activate the Document to true, and set the path in the options to the xml it worked fine, but thats a problem

Ty for your time and help :)

Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 7, 2017 2:13 AM   in response to: Thommy Ce in response to: Thommy Ce
El 07/06/2017 a las 10:45, Thommy Ce escribió:
Hello Antonio, well i tryied some things now, had much work and was stressed,
Now the followings on Method:

A) Worked

B) it says linking problem

Probably you don't have written the correct LoadXmlToListView
declaration or you have removed its implementation

C) Typename expected

You must include at the begin of the Form's header file the header files
where both TXMLDocument and TListView are declared:
#include <Vcl.ComCtrls.hpp>
#include <Xml.XMLDoc.hpp>


D) I get Typename expected

Same as C.

now im fine with A he compilies it.

But my XMLDocument needs to be active, and on the XMLDocument1 i need to set the FileName,
than it works, but what we have many XML files, thats why i want to choose the XML File from my PC.
Thats why i have an OpenFile button.

i Think i need something like
LoadXmlToListView(xml_table->xml_listview, xml_table->XMLDocument1->FileName = data_xml->Text); but this dont work
so i think i need do declare the XMLDocument1 somehow , that he takes the xml from the data_xml->Text path, im right ?

so i tryied this

void __fastcall TForm1::Xml_click1Click(TObject *Sender)
{
//fill the XMLDoc with the complete path

Visible = false;
xml_table -> Visible = true;
xml_table->XMLDocument1->FileName = data_xml->Text;

LoadXmlToListView(xml_table->xml_listview, xml_table->XMLDocument1);

}

Try this:

void __fastcall TForm1::Xml_click1Click(TObject *Sender)
{
	//fill the XMLDoc with the complete path
 
	Visible = false;
	xml_table -> Visible = true;
	xml_table->XMLDocument1->LoadFromFile(data_xml->Text);
 
	LoadXmlToListView(xml_table->xml_listview, xml_table->XMLDocument1);
}
Thommy Ce

Posts: 28
Registered: 6/17/17
Re: Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 7, 2017 2:27 AM   in response to: Antonio Estevez in response to: Antonio Estevez
Antonio Estevez wrote:
El 07/06/2017 a las 10:45, Thommy Ce escribió:
Hello Antonio, well i tryied some things now, had much work and was stressed,
Now the followings on Method:

A) Worked

B) it says linking problem

Probably you don't have written the correct LoadXmlToListView
declaration or you have removed its implementation

C) Typename expected

You must include at the begin of the Form's header file the header files
where both TXMLDocument and TListView are declared:
#include <Vcl.ComCtrls.hpp>
#include <Xml.XMLDoc.hpp>


D) I get Typename expected

Same as C.

now im fine with A he compilies it.

But my XMLDocument needs to be active, and on the XMLDocument1 i need to set the FileName,
than it works, but what we have many XML files, thats why i want to choose the XML File from my PC.
Thats why i have an OpenFile button.

i Think i need something like
LoadXmlToListView(xml_table->xml_listview, xml_table->XMLDocument1->FileName = data_xml->Text); but this dont work
so i think i need do declare the XMLDocument1 somehow , that he takes the xml from the data_xml->Text path, im right ?

so i tryied this

void __fastcall TForm1::Xml_click1Click(TObject *Sender)
{
//fill the XMLDoc with the complete path

Visible = false;
xml_table -> Visible = true;
xml_table->XMLDocument1->FileName = data_xml->Text;

LoadXmlToListView(xml_table->xml_listview, xml_table->XMLDocument1);

}

Try this:

void __fastcall TForm1::Xml_click1Click(TObject *Sender)
{
	//fill the XMLDoc with the complete path
 
	Visible = false;
	xml_table -> Visible = true;
	xml_table->XMLDocument1->LoadFromFile(data_xml->Text);
 
	LoadXmlToListView(xml_table->xml_listview, xml_table->XMLDocument1);
}

ah yeah i forgott the includes man... : D
ok im dumb, xml_table->XMLDocument1->LoadFromFile(data_xml->Text); this works now ,perfekt like i need it !

Ok i need only one more function, i will try it again if i can solve it :) and if not i will ask you :)
Thank you so much
Thommy Ce

Posts: 28
Registered: 6/17/17
Re: Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 20, 2017 1:09 AM   in response to: Antonio Estevez in response to: Antonio Estevez
Hello Antonio,

So i need your help i googled much but i think u can give me a better hint !
is it possible to sort the listview by row EndToEnd? i think because its a string so it would be hard to sort it because it has "EII12345678", "EII92837465".. and so on

or an other way but i think this is a complicated way, to compare both listviews EndtoEnd Rows if there are matches.
If u would give me a hint I would be thankfull :)

thanks for your time !

Edited by: Thommy Ce on Jun 20, 2017 1:09 AM
Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 20, 2017 2:11 AM   in response to: Thommy Ce in response to: Thommy Ce
El 20/06/2017 a las 10:09, Thommy Ce escribió:
Hello Antonio,

So i need your help i googled much but i think u can give me a better hint !
is it possible to sort the listview by row EndToEnd? i think because its a string so it would be hard to sort it because it has "EII12345678", "EII92837465".. and so on

Call the TListView's AlphaSort() function:

void __fastcall LoadXmlToListView(TListView *ListView, TXMLDocument *XMLDoc)
{
    ListView->Clear();
    AddNodeToListView(ListView, XMLDoc->DocumentElement);
 
    ListView->AlphaSort();
}


or an other way but i think this is a complicated way, to compare both listviews EndtoEnd Rows if there are matches.
If u would give me a hint I would be thankfull :)

The following code iterated throw the ListView1 items and check if
ListView2 has an item with the same Caption:

    TListItems *List1= ListView1->Items;
    TListItems *List2= ListView2->Items;
 
    for (int Index1= 0; Index1< List1->Count; ++Index1)
    {
       TListItem *Item1= List1->Item[Index1];
       String Text= Item1->Caption;
 
       int Index2= List2->Count;
       while (--Index2 >= 0)
       {
          TListItem *Item2= List2->Item[Index2];
 
          int Comp= Text.Compare(Item2->Caption);
          if (Comp> 0)
             break;
 
          if (Comp== 0) //  Item1 & Item2 match
          {
             // Use Item1 and/or Item2 as needed
 
             break;
          }
       }
    }


Note that this code assumes that ListView2 is alphabetically sorted.

Captions are compared case-sensitive. If you want compare without
case-sensitive then replace
    int Comp= Text.Compare(Item2->Caption);


with

    int Comp= Text.CompareIC(Item2->Caption);
Thommy Ce

Posts: 28
Registered: 6/17/17
Re: Help with csv and listview [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 20, 2017 4:34 AM   in response to: Antonio Estevez in response to: Antonio Estevez
Antonio Estevez wrote:
El 20/06/2017 a las 10:09, Thommy Ce escribió:
Hello Antonio,

So i need your help i googled much but i think u can give me a better hint !
is it possible to sort the listview by row EndToEnd? i think because its a string so it would be hard to sort it because it has "EII12345678", "EII92837465".. and so on

Call the TListView's AlphaSort() function:

void __fastcall LoadXmlToListView(TListView *ListView, TXMLDocument *XMLDoc)
{
    ListView->Clear();
    AddNodeToListView(ListView, XMLDoc->DocumentElement);
 
    ListView->AlphaSort();
}


or an other way but i think this is a complicated way, to compare both listviews EndtoEnd Rows if there are matches.
If u would give me a hint I would be thankfull :)

The following code iterated throw the ListView1 items and check if
ListView2 has an item with the same Caption:

    TListItems *List1= ListView1->Items;
    TListItems *List2= ListView2->Items;
 
    for (int Index1= 0; Index1< List1->Count; ++Index1)
    {
       TListItem *Item1= List1->Item[Index1];
       String Text= Item1->Caption;
 
       int Index2= List2->Count;
       while (--Index2 >= 0)
       {
          TListItem *Item2= List2->Item[Index2];
 
          int Comp= Text.Compare(Item2->Caption);
          if (Comp< 0)
             break;
 
          if (Comp== 0) //  Item1 & Item2 match
          {
             // Use Item1 and/or Item2 as needed
          }
       }
    }


Note that this code assumes that ListView2 is alphabetically sorted.

Captions are compared case-sensitive. If you want compare without
case-sensitive then replace
    int Comp= Text.Compare(Item2->Caption);


with

    int Comp= Text.CompareIC(Item2->Caption);

Oh wow so easy with AlphaSort() i didnt found it o.O
ok about the compare,
my csv and xml are in 2 differet tables,
i thought i would make an third tabel result_table.
Here i would need again a listview , and than the code should compare it in the third one ?
or should i make in the third table the listview1, listview2. now the compare funktion
and would he only show me the matched one ?

Ty Antonio!

Edited by: Thommy Ce on Jun 20, 2017 5:33 AM

Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 20, 2017 8:03 AM   in response to: Thommy Ce in response to: Thommy Ce
El 20/06/2017 a las 14:33, Thommy Ce escribió:
ok about the compare,
my csv and xml are in 2 differet tables,
i thought i would make an third tabel result_table.
Here i would need again a listview , and than the code should compare it in the third one ?
or should i make in the third table the listview1, listview2. now the compare funktion
and would he only show me the matched one ?


I don't know the name of your two TListView components so you must
replace, by example, ListView1 with the component that contains the csv
data and ListView2 with the component that contains the xml data.

To add the matching items to the third TListView just do this:

   TListItems *List1= ListView2->Items;
   TListItems *List2= ListView1->Items;
   TListItems *List3= ListView3->Items;
 
   for (int Index1= 0, Index2= 0; Index1< List1->Count; ++Index1)
   {
      TListItem *Item1= List1->Item[Index1];
      String Text= Item1->Caption;
 
      while (Index2< List2->Count)
      {
         TListItem *Item2= List2->Item[Index2];
 
         int Comp= Text.Compare(Item2->Caption);
         if (Comp< 0)
            break;
 
         Index2++;
 
         if (Comp== 0) //  Item1 & Item2 match
         {
            TListItem *Item3= List3->Add();
 
            Item3->Caption = Item1->Caption;
            Item3->SubItems= Item1->SubItems;
            break;
         }
      }
   }


You must replace ListView3 with your third TListView component.

Note that now both ListView1 and ListView2 must be alphabetically sorted.
Thommy Ce

Posts: 28
Registered: 6/17/17
Re: Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 22, 2017 7:21 AM   in response to: Antonio Estevez in response to: Antonio Estevez
Antonio Estevez wrote:
El 20/06/2017 a las 14:33, Thommy Ce escribió:
ok about the compare,
my csv and xml are in 2 differet tables,
i thought i would make an third tabel result_table.
Here i would need again a listview , and than the code should compare it in the third one ?
or should i make in the third table the listview1, listview2. now the compare funktion
and would he only show me the matched one ?


I don't know the name of your two TListView components so you must
replace, by example, ListView1 with the component that contains the csv
data and ListView2 with the component that contains the xml data.

To add the matching items to the third TListView just do this:

   TListItems *List1= ListView2->Items;
   TListItems *List2= ListView1->Items;
   TListItems *List3= ListView3->Items;
 
   for (int Index1= 0, Index2= 0; Index1< List1->Count; ++Index1)
   {
      TListItem *Item1= List1->Item[Index1];
      String Text= Item1->Caption;
 
      while (Index2< List2->Count)
      {
         TListItem *Item2= List2->Item[Index2];
 
         int Comp= Text.Compare(Item2->Caption);
         if (Comp< 0)
            break;
 
         Index2++;
 
         if (Comp== 0) //  Item1 & Item2 match
         {
            TListItem *Item3= List3->Add();
 
            Item3->Caption = Item1->Caption;
            Item3->SubItems= Item1->SubItems;
            break;
         }
      }
   }


You must replace ListView3 with your third TListView component.

Note that now both ListView1 and ListView2 must be alphabetically sorted.

Hello Antonio,

Well i have now 3 Tables 1 table is its own .cpp
I got xml_table, csv_table, and now the new result_table.
i think i can mange to replace the listview to the right components.

xml and the csv_tabe alre both AlphaSorted(): and stioll works on both tables ( thank you )

now for the compare, shall i use this code on the result_table?
than fix the components to the right ?

to remember, first im loading the xml and csv on my main_table, and displaying it on the Xml /csv Table by a button click.
so now i think if im writing this.
I need the compare funktion in my button which opens the compare_table and the 3 listview ?
so thats for me logical and i will try this tomorrow :)
i hope i am right

Ty for your help and time :)
Thommy Ce

Posts: 28
Registered: 6/17/17
Re: Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 26, 2017 1:41 AM   in response to: Thommy Ce in response to: Thommy Ce

Hello Antonio,

Well i have now 3 Tables 1 table is its own .cpp
I got xml_table, csv_table, and now the new result_table.
i think i can mange to replace the listview to the right components.

xml and the csv_tabe alre both AlphaSorted(): and stioll works on both tables ( thank you )

now for the compare, shall i use this code on the result_table?
than fix the components to the right ?

to remember, first im loading the xml and csv on my main_table, and displaying it on the Xml /csv Table by a button click.
so now i think if im writing this.
I need the compare funktion in my button which opens the compare_table and the 3 listview ?
so thats for me logical and i will try this tomorrow :)
i hope i am right

Ty for your help and time :)

Hello Antonio !
Thanks, i did it to work, i just needed to change the names to the right format, was an easy one.
So now my Porgramm should be finished, but I have a question about the compare.
The 3 Listview show only the matched one right ?
i think it would be better, if he shows me the items where are NOT matched !,
so i can faster find the problem in our dokument.

Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 26, 2017 2:49 AM   in response to: Thommy Ce in response to: Thommy Ce
El 26/06/2017 a las 10:41, Thommy Ce escribió:

Hello Antonio !
Thanks, i did it to work, i just needed to change the names to the right format, was an easy one.
So now my Porgramm should be finished, but I have a question about the compare.
The 3 Listview show only the matched one right ?
i think it would be better, if he shows me the items where are NOT matched !,
so i can faster find the problem in our dokument.

I think the best thing in this case would be to display in red color the
text of the elements that do not match and get ride of the result_table.

First add an OnCustomDrawItem event to both xml_table and csv_table:
void __fastcall TForm21::csv_tableCustomDrawItem(
    TCustomListView *Sender, TListItem *Item,
    TCustomDrawState State, bool &DefaultDraw)
{
    if (Item->Data!= NULL)
    {
       Sender->Canvas->Font->Color= clRed;
    }
 
}

Add the following function to compare the tables (remember that both
tabes must be alphabetically sorted):

void __fastcall CompareData(TListView *ListView1, TListView *ListView2)
{
    TListItems *List1= ListView1->Items;
    TListItems *List2= ListView2->Items;
 
    for (int Index1= 0, Index2= 0; Index1< List1->Count; ++Index1)
    {
       TListItem *Item1= List1->Item[Index1];
       String Text= Item1->Caption;
 
       while (Index2< List2->Count)
       {
          TListItem *Item2= List2->Item[Index2];
 
          int Comp= Text.Compare(Item2->Caption);
          if (Comp< 0)
          {
             Item1->Data= (void*)1;
             break;
          }
 
          Index2++;
 
          if (Comp== 0) //  Item1 & Item2 match
             break;
       }
    }
    ListView1->Invalidate(); // Redraw the ListView
}


Finally, call the function twice:
    // Search for elements of csv_table that are not in xml_table
    CompareData(csv_table, xml_table);
    // Search for elements of xml_table that are not in csv_table
    CompareData(xml_table, csv_table);
Thommy Ce

Posts: 28
Registered: 6/17/17
Re: Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 26, 2017 5:59 AM   in response to: Antonio Estevez in response to: Antonio Estevez

I think the best thing in this case would be to display in red color the
text of the elements that do not match and get ride of the result_table.

First add an OnCustomDrawItem event to both xml_table and csv_table:
void __fastcall TForm21::csv_tableCustomDrawItem(
    TCustomListView *Sender, TListItem *Item,
    TCustomDrawState State, bool &DefaultDraw)
{
    if (Item->Data!= NULL)
    {
       Sender->Canvas->Font->Color= clRed;
    }
 
}

Add the following function to compare the tables (remember that both
tabes must be alphabetically sorted):

void __fastcall CompareData(TListView *ListView1, TListView *ListView2)
{
    TListItems *List1= ListView1->Items;
    TListItems *List2= ListView2->Items;
 
    for (int Index1= 0, Index2= 0; Index1< List1->Count; ++Index1)
    {
       TListItem *Item1= List1->Item[Index1];
       String Text= Item1->Caption;
 
       while (Index2< List2->Count)
       {
          TListItem *Item2= List2->Item[Index2];
 
          int Comp= Text.Compare(Item2->Caption);
          if (Comp< 0)
          {
             Item1->Data= (void*)1;
             break;
          }
 
          Index2++;
 
          if (Comp== 0) //  Item1 & Item2 match
             break;
       }
    }
    ListView1->Invalidate(); // Redraw the ListView
}


Finally, call the function twice:
    // Search for elements of csv_table that are not in xml_table
    CompareData(csv_table, xml_table);
    // Search for elements of xml_table that are not in csv_table
    CompareData(xml_table, csv_table);

Hello Antonio,

So i did first

void __fastcall TForm21::csv_tableCustomDrawItem(
TCustomListView *Sender, TListItem *Item,
TCustomDrawState State, bool &DefaultDraw)
{
if (Item->Data!= NULL)
{
Sender->Canvas->Font->Color= clRed;
}

}
and got on the xml and csv_table funktion csv_tableCustomDrawItem;

than i toot the compare funktion and changes the listview names and path to my one.

here im a bit confuse, i dont know.. i think i missed something because.
if open my third table. the compare table ( third listview)
nothing happen.

i Think my problem is, or i dont know how, but i got the thrid listview in an extra table, csv and xml are listed in there, in 3 rows
both are Alphasorted.
There is no red marker, but im sure there are some missing counts.

void __fastcall TForm1::m_nextClick(TObject *Sender)
{
 
	if(MessageBox(NULL, L"Sind sie sicher das sie Fortfahren möchten ?", L"Einlesen der Dateien",  MB_YESNOCANCEL) == IDYES)
	{
	// third Ttble
	auswertung_table ->Visible =true;
	Visible =false;
 
	// Xml loading
	xml_table->XMLDocument1->LoadFromFile(data_xml->Text);
	LoadXmlToListView(auswertung_table->listview3, xml_table->XMLDocument1);
 
	auswertung_table->XMLDocument1->LoadFromFile(data_xml->Text);
	LoadXmlToListView(auswertung_table->listview3, auswertung_table->XMLDocument1);
 
	//Csv loading
		TStringList *CsvFile= new TStringList();
	try
	{
	   CsvFile->LoadFromFile(data_csv->Text);
 
	   TStringList *CsvRow= new TStringList();
	   try
	   {
		  CsvRow->Delimiter= ';';
		  CsvRow->QuoteChar= '"';
		  CsvRow->StrictDelimiter= true;
 
		  for (int Row= 0; Row< CsvFile->Count; ++Row)
		  {
			 CsvRow->DelimitedText= CsvFile->Strings[Row];
 
			 TListItem *Item= csv_table->ListView1->Items->Add();
			 Item->Caption= CsvRow->Strings[0];
			 for (int Col= 1; Col< CsvRow->Count; ++Col)
				Item->SubItems->Add(CsvRow->Strings[Col]);
 
				csv_table->ListView1->AlphaSort();
		  }
	   }
	   __finally
	   {
		  delete CsvRow;
	   }
	}
	__finally
	{
	   delete CsvFile;
	}
 
 
	//Compare
	CompareData(csv_table->ListView1, xml_table->xml_listview);
	CompareData(xml_table->xml_listview, csv_table->ListView1);
 
 
 
 
	}
	else
	{
 
	}
}


on this code, im loading the xml file and the csv file to the third listview3 in the new table.
on the end there is the compare funktion twice like u said,
the goes well and i gont get any errors, but i thinkn im still missing something for the view...
i think somethink sis wrong with the third listview3 in my new table.
or i need do display listview 1 and 2 again in the third table ?
do u have any ideas ?
if u want i can post the fullcode if it helps

Edited by: Thommy Ce on Jun 26, 2017 6:00 AM
Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: Help with csv and listview [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 26, 2017 7:55 AM   in response to: Thommy Ce in response to: Thommy Ce
El 26/06/2017 a las 15:00, Thommy Ce escribió:
Hello Antonio,

So i did first

void __fastcall TForm21::csv_tableCustomDrawItem(
TCustomListView *Sender, TListItem *Item,
TCustomDrawState State, bool &DefaultDraw)
{
if (Item->Data!= NULL)
{
Sender->Canvas->Font->Color= clRed;
}

}
and got on the xml and csv_table funktion csv_tableCustomDrawItem;

than i toot the compare funktion and changes the listview names and path to my one.

here im a bit confuse, i dont know.. i think i missed something because.
if open my third table. the compare table ( third listview)
nothing happen.

i Think my problem is, or i dont know how, but i got the thrid listview in an extra table, csv and xml are listed in there, in 3 rows
both are Alphasorted.
There is no red marker, but im sure there are some missing counts.

void __fastcall TForm1::m_nextClick(TObject *Sender)
{
 
	if(MessageBox(NULL, L"Sind sie sicher das sie Fortfahren möchten ?", L"Einlesen der Dateien",  MB_YESNOCANCEL) == IDYES)
	{
	// third Ttble
	auswertung_table ->Visible =true;
	Visible =false;
 
	// Xml loading
	xml_table->XMLDocument1->LoadFromFile(data_xml->Text);
	LoadXmlToListView(auswertung_table->listview3, xml_table->XMLDocument1);
 
	auswertung_table->XMLDocument1->LoadFromFile(data_xml->Text);
	LoadXmlToListView(auswertung_table->listview3, auswertung_table->XMLDocument1);
 
	//Csv loading
		TStringList *CsvFile= new TStringList();
	try
	{
	   CsvFile->LoadFromFile(data_csv->Text);
 
	   TStringList *CsvRow= new TStringList();
	   try
	   {
		  CsvRow->Delimiter= ';';
		  CsvRow->QuoteChar= '"';
		  CsvRow->StrictDelimiter= true;
 
		  for (int Row= 0; Row< CsvFile->Count; ++Row)
		  {
			 CsvRow->DelimitedText= CsvFile->Strings[Row];
 
			 TListItem *Item= csv_table->ListView1->Items->Add();
			 Item->Caption= CsvRow->Strings[0];
			 for (int Col= 1; Col< CsvRow->Count; ++Col)
				Item->SubItems->Add(CsvRow->Strings[Col]);
 
				csv_table->ListView1->AlphaSort();

You are sorting the list each time a new row is added to it.
You don't need do that. Move that line just before the calls to CompareData.

		  }
	   }
	   __finally
	   {
		  delete CsvRow;
	   }
	}
	__finally
	{
	   delete CsvFile;
	}
 

csv_table->ListView1->AlphaSort(); // <--- Here

 
	//Compare
	CompareData(csv_table->ListView1, xml_table->xml_listview);
	CompareData(xml_table->xml_listview, csv_table->ListView1);
 
 
 
 
	}
	else
	{
 
	}
}


on this code, im loading the xml file and the csv file to the third listview3 in the new table.
on the end there is the compare funktion twice like u said,
the goes well and i gont get any errors, but i thinkn im still missing something for the view...
i think somethink sis wrong with the third listview3 in my new table.

Note that I removed the code which add the items to the third list
because I think that it is not necessary since the items that don't
match will be in red color in their own list..

When an item from the first list is not in the second list I set the
value of its Data property to 1.
When an item in the list is to be drawn the OnCustomDrawItem event is
called; then I set the font color to red if the Data property of that
item is not NULL.

If you still want the items that do not match the third list then modify
the CompareData function like this:
void __fastcall CompareData(TListView *ListView1, TListView *ListView2, TListView *ListView3)
{
    TListItems *List1= ListView1->Items;
    TListItems *List2= ListView2->Items;
    TListItems *List3= ListView3->Items;
 
    for (int Index1= 0, Index2= 0; Index1< List1->Count; ++Index1)
    {
       TListItem *Item1= List1->Item[Index1];
       String Text= Item1->Caption;
 
       while (Index2< List2->Count)
       {
          TListItem *Item2= List2->Item[Index2];
 
          int Comp= Text.Compare(Item2->Caption);
          if (Comp< 0)
          {
             Item1->Data= (void*)1;
 
             TListItem *Item3= List3->Add();
             Item3->Caption = Item1->Caption;
             Item3->SubItems= Item1->SubItems;
             break;
          }
 
          Index2++;
 
          if (Comp== 0) //  Item1 & Item2 match
             break;
       }
    }
    ListView1->Invalidate(); // Redraw the ListView
}


	//Compare
	CompareData(csv_table->ListView1, xml_table->xml_listview, result_table);
	CompareData(xml_table->xml_listview, csv_table->ListView1, result_table);
 
         // Sort the result table
         result_table->AlphaSort();

or i need do display listview 1 and 2 again in the third table ?
do u have any ideas ?

I think that you have not correctly created/assigned the
OnCustomDrawItem event for the two ListView components.

if u want i can post the fullcode if it helps

You can ZIP the .cpp, .h and .cbproj files and upload it to the
Attachments group:
https://forums.embarcadero.com/forum.jspa?forumID=2

Then post the link here.
Thommy Ce

Posts: 28
Registered: 6/17/17
Re: Help with csv and listview [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 26, 2017 11:49 PM   in response to: Antonio Estevez in response to: Antonio Estevez
Hello Antonio,

https://forums.embarcadero.com/thread.jspa?threadID=252151&stqc=true here is the link for the cpp. and h.
i have few more table but they are not so important, this IHK_Projekt.cpp is the main cpp with all the functions.
i will check your hints, but i would be glad if u can check my cpp.

// Edit, ok zipped the other files to now it should be complete

thank you :)

Edited by: Thommy Ce on Jun 26, 2017 11:56 PM
Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: Help with csv and listview [Edit] [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 27, 2017 2:02 AM   in response to: Thommy Ce in response to: Thommy Ce
El 27/06/2017 a las 08:57, Thommy Ce escribió:
Hello Antonio,

https://forums.embarcadero.com/thread.jspa?threadID=252151&stqc=true here is the link for the cpp. and h.
i have few more table but they are not so important, this IHK_Projekt.cpp is the main cpp with all the functions.
i will check your hints, but i would be glad if u can check my cpp.

// Edit, ok zipped the other files to now it should be complete

thank you :)

Edited by: Thommy Ce on Jun 26, 2017 11:56 PM

I just upload a zip file with modified files but I have not been able to
verify if they work properly.

Thommy Ce

Posts: 28
Registered: 6/17/17
Re: Help with csv and listview [Edit] [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 27, 2017 2:54 AM   in response to: Antonio Estevez in response to: Antonio Estevez
Antonio Estevez wrote:
El 27/06/2017 a las 08:57, Thommy Ce escribió:
Hello Antonio,

https://forums.embarcadero.com/thread.jspa?threadID=252151&stqc=true here is the link for the cpp. and h.
i have few more table but they are not so important, this IHK_Projekt.cpp is the main cpp with all the functions.
i will check your hints, but i would be glad if u can check my cpp.

// Edit, ok zipped the other files to now it should be complete

thank you :)

Edited by: Thommy Ce on Jun 26, 2017 11:56 PM

I just upload a zip file with modified files but I have not been able to
verify if they work properly.


i just checked it, there was no problem with it and compiled perfectly,
but the compare still dont work


void __fastcall TForm1::m_nextClick(TObject *Sender)
{
 
	if(MessageBox(NULL, L"Sind sie sicher das sie Fortfahren möchten ?", L"Einlesen der Dateien",  MB_YESNOCANCEL) == IDYES)
	{
		// third Ttble
		auswertung_table ->Visible =true;
		Visible =false;
 
		// Xml loading
		xml_table->XMLDocument1->LoadFromFile(data_xml->Text);
		LoadXmlToListView(auswertung_table->listview3, xml_table->XMLDocument1);
 
		auswertung_table->XMLDocument1->LoadFromFile(data_xml->Text);
		LoadXmlToListView(auswertung_table->listview3, auswertung_table->XMLDocument1);
 
		// Csv loading
		LoadCsvToListView(csv_table->ListView1, data_csv->Text);
 
		// Compare
		// Replace NULL with the result table listview if you want to view
		// the items that don't match in that table
		CompareData(csv_table->ListView1, xml_table->xml_listview, auswertung_table->listview3);
		CompareData(xml_table->xml_listview, csv_table->ListView1, auswertung_table->listview3);
 
	}
	else
	{
 
	}
 
}


on the comapre i used my thrid listview and replaced the NULL like u said in the comment,
but the listview still shows me all entrys and not only the ones whos not matched, or all are not matched,
i will get a new xml and csv for a test.

but still the red color does not work

//edit:

i checked with notepad++ the xml and the csv i have, so they are fine.
also the problem is that the dont displays me the not matched one, just all entrys

Edited by: Thommy Ce on Jun 27, 2017 2:57 AM
Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: Help with csv and listview [Edit] [Edit]
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 27, 2017 4:03 AM   in response to: Thommy Ce in response to: Thommy Ce
El 27/06/2017 a las 11:54, Thommy Ce escribió:

on the comapre i used my thrid listview and replaced the NULL like u said in the comment,
but the listview still shows me all entrys and not only the ones whos not matched, or all are not matched,

Works for me using random data as you can see in the image that I have
uploaded to the Attachments group.

Note that you are loading the XML file in the third table:

		// Xml loading
		xml_table->XMLDocument1->LoadFromFile(data_xml->Text);
		LoadXmlToListView(auswertung_table->listview3, xml_table->XMLDocument1);
 
		auswertung_table->XMLDocument1->LoadFromFile(data_xml->Text);
		LoadXmlToListView(auswertung_table->listview3, auswertung_table->XMLDocument1);

i will get a new xml and csv for a test.

but still the red color does not work

Probably because when you press the buttons to open the tables you
reload the data from the files.

Please call AlphaSort() for the third table after the calls to CompareData:
		// Compare
		CompareData(csv_table->ListView1, xml_table->xml_listview, auswertung_table->listview3);
		CompareData(xml_table->xml_listview, csv_table->ListView1, auswertung_table->listview3);
 
		auswertung_table->listview3->AlphaSort();  //<--- Add this line


Sorry but I don't undertand the logic of the program flow.
Why do you hide the main form when you open a new form?
The main form never is shown when the new form is closed. Then there is
no way to close the application because the main form is hidden
So only one of the forms with the tables can be viewed at any time.
Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 27, 2017 4:30 AM   in response to: Antonio Estevez in response to: Antonio Estevez
El 27/06/2017 a las 13:26, Antonio Estevez escribió:
El 27/06/2017 a las 11:54, Thommy Ce escribió:

on the comapre i used my thrid listview and replaced the NULL like u said in the comment,
but the listview still shows me all entrys and not only the ones whos not matched, or all are not matched,

Definitely the m_nextClick procedure should be like this
void __fastcall TForm1::m_nextClick(TObject *Sender)
{
 
	if(MessageBox(NULL, L"Sind sie sicher das sie Fortfahren möchten ?", L"Einlesen der Dateien",  MB_YESNOCANCEL) == IDYES)
	{
		// third Table
		auswertung_table->listview3->Clear();
		auswertung_table ->Visible =true;
		Visible =false;
 
		// Xml loading
		xml_table->XMLDocument1->LoadFromFile(data_xml->Text);
		LoadXmlToListView(xml_table->xml_listview, xml_table->XMLDocument1);
 
		// Csv loading
		LoadCsvToListView(csv_table->ListView1, data_csv->Text);
 
		// Compare
		CompareData(csv_table->ListView1, xml_table->xml_listview, auswertung_table->listview3);
		CompareData(xml_table->xml_listview, csv_table->ListView1, auswertung_table->listview3);
 
		auswertung_table->listview3->AlphaSort();
	}
	else
	{
 
	}
}
Thommy Ce

Posts: 28
Registered: 6/17/17
Re: Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 28, 2017 12:02 AM   in response to: Antonio Estevez in response to: Antonio Estevez
Antonio Estevez wrote:
El 27/06/2017 a las 13:26, Antonio Estevez escribió:
El 27/06/2017 a las 11:54, Thommy Ce escribió:

on the comapre i used my thrid listview and replaced the NULL like u said in the comment,
but the listview still shows me all entrys and not only the ones whos not matched, or all are not matched,

Definitely the m_nextClick procedure should be like this
void __fastcall TForm1::m_nextClick(TObject *Sender)
{
 
	if(MessageBox(NULL, L"Sind sie sicher das sie Fortfahren möchten ?", L"Einlesen der Dateien",  MB_YESNOCANCEL) == IDYES)
	{
		// third Table
		auswertung_table->listview3->Clear();
		auswertung_table ->Visible =true;
		Visible =false;
 
		// Xml loading
		xml_table->XMLDocument1->LoadFromFile(data_xml->Text);
		LoadXmlToListView(xml_table->xml_listview, xml_table->XMLDocument1);
 
		// Csv loading
		LoadCsvToListView(csv_table->ListView1, data_csv->Text);
 
		// Compare
		CompareData(csv_table->ListView1, xml_table->xml_listview, auswertung_table->listview3);
		CompareData(xml_table->xml_listview, csv_table->ListView1, auswertung_table->listview3);
 
		auswertung_table->listview3->AlphaSort();
	}
	else
	{
 
	}
}

Hello Antonio,

Jeah my Xml and Csv table are not relevant, i just added them to check if my xml and csv are loading....
i have a MainMenu with a back button, so i can go back to the Main table and close the Programm.

i checked with modyfied files, the EndToEnd Data row disappear after i hit the next button fot the compare table.
i tried now this, XML file with 2 data and an csv file with one data, the data in the csv has one matched with the xml

after the click, my csv data disappear and my row EndToEnd
the 2 Datas from the xml are listed

i dont get the problem
Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 28, 2017 12:57 AM   in response to: Thommy Ce in response to: Thommy Ce
El 28/06/2017 a las 09:02, Thommy Ce escribió:
Antonio Estevez wrote:
El 27/06/2017 a las 13:26, Antonio Estevez escribió:
El 27/06/2017 a las 11:54, Thommy Ce escribió:

on the comapre i used my thrid listview and replaced the NULL like u said in the comment,
but the listview still shows me all entrys and not only the ones whos not matched, or all are not matched,

Definitely the m_nextClick procedure should be like this
void __fastcall TForm1::m_nextClick(TObject *Sender)
{
 
	if(MessageBox(NULL, L"Sind sie sicher das sie Fortfahren möchten ?", L"Einlesen der Dateien",  MB_YESNOCANCEL) == IDYES)
	{
		// third Table
		auswertung_table->listview3->Clear();
		auswertung_table ->Visible =true;
		Visible =false;
 
		// Xml loading
		xml_table->XMLDocument1->LoadFromFile(data_xml->Text);
		LoadXmlToListView(xml_table->xml_listview, xml_table->XMLDocument1);
 
		// Csv loading
		LoadCsvToListView(csv_table->ListView1, data_csv->Text);
 
		// Compare
		CompareData(csv_table->ListView1, xml_table->xml_listview, auswertung_table->listview3);
		CompareData(xml_table->xml_listview, csv_table->ListView1, auswertung_table->listview3);
 
		auswertung_table->listview3->AlphaSort();
	}
	else
	{
 
	}
}

Hello Antonio,

Jeah my Xml and Csv table are not relevant, i just added them to check if my xml and csv are loading....
i have a MainMenu with a back button, so i can go back to the Main table and close the Programm.

What happens if the user press the [X] close button from the title bar?
Or he press Ctrl+F4 keys?

You should use the OnClose event to show the main form.

i checked with modyfied files, the EndToEnd Data row disappear after i hit the next button fot the compare table.
i tried now this, XML file with 2 data and an csv file with one data, the data in the csv has one matched with the xml

after the click, my csv data disappear and my row EndToEnd
the 2 Datas from the xml are listed

i dont get the problem

Please, upload the project files again to the Attachements group.
Also upload the xml and csv files.
Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 28, 2017 1:28 AM   in response to: Antonio Estevez in response to: Antonio Estevez
El 28/06/2017 a las 09:57, Antonio Estevez escribió:
Hello Antonio,

Jeah my Xml and Csv table are not relevant, i just added them to check if my xml and csv are loading....
i have a MainMenu with a back button, so i can go back to the Main table and close the Programm.

What happens if the user press the [X] close button from the title bar?
Or he press Ctrl+F4 keys?

You should use the OnClose event to show the main form.

i checked with modyfied files, the EndToEnd Data row disappear after i hit the next button fot the compare table.
i tried now this, XML file with 2 data and an csv file with one data, the data in the csv has one matched with the xml

after the click, my csv data disappear and my row EndToEnd
the 2 Datas from the xml are listed

i dont get the problem

Please, upload the project files again to the Attachements group.
Also upload the xml and csv files.

Currently the CompareData function compares the value of the first
column of each listview. Which column in the XML listview and which
column in the CSV listview should be compared?

Thommy Ce

Posts: 28
Registered: 6/17/17
Re: Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 28, 2017 1:37 AM   in response to: Antonio Estevez in response to: Antonio Estevez
Antonio Estevez wrote:
El 28/06/2017 a las 09:02, Thommy Ce escribió:
Antonio Estevez wrote:
El 27/06/2017 a las 13:26, Antonio Estevez escribió:
El 27/06/2017 a las 11:54, Thommy Ce escribió:

on the comapre i used my thrid listview and replaced the NULL like u said in the comment,
but the listview still shows me all entrys and not only the ones whos not matched, or all are not matched,

Definitely the m_nextClick procedure should be like this
void __fastcall TForm1::m_nextClick(TObject *Sender)
{
 
	if(MessageBox(NULL, L"Sind sie sicher das sie Fortfahren möchten ?", L"Einlesen der Dateien",  MB_YESNOCANCEL) == IDYES)
	{
		// third Table
		auswertung_table->listview3->Clear();
		auswertung_table ->Visible =true;
		Visible =false;
 
		// Xml loading
		xml_table->XMLDocument1->LoadFromFile(data_xml->Text);
		LoadXmlToListView(xml_table->xml_listview, xml_table->XMLDocument1);
 
		// Csv loading
		LoadCsvToListView(csv_table->ListView1, data_csv->Text);
 
		// Compare
		CompareData(csv_table->ListView1, xml_table->xml_listview, auswertung_table->listview3);
		CompareData(xml_table->xml_listview, csv_table->ListView1, auswertung_table->listview3);
 
		auswertung_table->listview3->AlphaSort();
	}
	else
	{
 
	}
}

Hello Antonio,

Jeah my Xml and Csv table are not relevant, i just added them to check if my xml and csv are loading....
i have a MainMenu with a back button, so i can go back to the Main table and close the Programm.

What happens if the user press the [X] close button from the title bar?
Or he press Ctrl+F4 keys?

You should use the OnClose event to show the main form.

i checked with modyfied files, the EndToEnd Data row disappear after i hit the next button fot the compare table.
i tried now this, XML file with 2 data and an csv file with one data, the data in the csv has one matched with the xml

after the click, my csv data disappear and my row EndToEnd
the 2 Datas from the xml are listed

i dont get the problem

Please, upload the project files again to the Attachements group.
Also upload the xml and csv files.

Jeah u right with the (x) the programm still running, so i will change it ! ty
https://forums.embarcadero.com/messageview.jspa?messageID=890536&stqc=true the files are uploaded and the csv and the xml
Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 28, 2017 3:43 AM   in response to: Thommy Ce in response to: Thommy Ce
El 28/06/2017 a las 10:37, Thommy Ce escribió:

Jeah u right with the (x) the programm still running, so i will change it ! ty
https://forums.embarcadero.com/messageview.jspa?messageID=890536&stqc=true the files are uploaded and the csv and the xml

I just uploaded modified files to the Attachments group.

- Added an OnClose event to all child forms to show the main form

- Added an OnCompare event to the CSV listview to sort the items by the
#8 column (UDF_EndeZuEnde)

- The first line of the CSV file contains the column names. Now the
LoadCsvToListView function skips this line.

- Added two new parameters to the CompareData function for the columns
which must be compared (#0 for the XML listview and #8 for the CSV
listview).
Thommy Ce

Posts: 28
Registered: 6/17/17
Re: Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 28, 2017 6:51 AM   in response to: Antonio Estevez in response to: Antonio Estevez
Antonio Estevez wrote:
El 28/06/2017 a las 10:37, Thommy Ce escribió:

Jeah u right with the (x) the programm still running, so i will change it ! ty
https://forums.embarcadero.com/messageview.jspa?messageID=890536&stqc=true the files are uploaded and the csv and the xml

I just uploaded modified files to the Attachments group.

- Added an OnClose event to all child forms to show the main form

- Added an OnCompare event to the CSV listview to sort the items by the
#8 column (UDF_EndeZuEnde)

- The first line of the CSV file contains the column names. Now the
LoadCsvToListView function skips this line.

- Added two new parameters to the CompareData function for the columns
which must be compared (#0 for the XML listview and #8 for the CSV
listview).

awesome it worked now with my test data, will test it with larger files :)
ty so much

Thommy Ce

Posts: 28
Registered: 6/17/17
Re: Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 4, 2017 1:08 AM   in response to: Thommy Ce in response to: Thommy Ce
Thommy Ce wrote:
Antonio Estevez wrote:
El 28/06/2017 a las 10:37, Thommy Ce escribió:

Jeah u right with the (x) the programm still running, so i will change it ! ty
https://forums.embarcadero.com/messageview.jspa?messageID=890536&stqc=true the files are uploaded and the csv and the xml

I just uploaded modified files to the Attachments group.

- Added an OnClose event to all child forms to show the main form

- Added an OnCompare event to the CSV listview to sort the items by the
#8 column (UDF_EndeZuEnde)

- The first line of the CSV file contains the column names. Now the
LoadCsvToListView function skips this line.

- Added two new parameters to the CompareData function for the columns
which must be compared (#0 for the XML listview and #8 for the CSV
listview).

awesome it worked now with my test data, will test it with larger files :)
ty so much


Hello Antonio,
just wanted u to know , it works like it should now
ty for your help really !
for now i can try some new thing , and playing arround !
thanks
Thommy Ce

Posts: 28
Registered: 6/17/17
Re: Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 6, 2017 6:50 AM   in response to: Thommy Ce in response to: Thommy Ce
Hello Antonio, can you explain me the Comparefunktion ? i dont get it exactly
I have 2(3) questions, i marked it with <---- //question
I hope u have the last patience to explaim me this :)
Thank You!

void __fastcall CompareData(
TListView *ListView1, int Column1,
TListView *ListView2, int Column2,
TListView *ListView3)
{
TListItems *List1 = ListView1->Items;
TListItems *List2 = ListView2->Items;

for (int Index1= 0, Index2= 0; Index1< List1->Count; ++Index1)
{
TListItem *Item1= List1->Item[Index1];
String Text1= Column1== 0 ? Item1->Caption :
Item1->SubItems->Strings[Column1-1]; <----- / / What happens here with Column1-1 ? and int Compare = -1 ?
int Compare= -1;

while (Index2< List2->Count)
{
TListItem *Item2= List2->Item[Index2];
String Text2= Column2== 0 ? Item2->Caption :
Item2->SubItems->Strings[Column2-1]; <----- // so i think if u can explain this one above it should be logicly the same

Compare= Text1.Compare(Text2);
if (Compare< 0)
break;

Index2++;

if (Compare== 0)
break;
}

if (Compare< 0)
{
Item1->Data= (void*)1; <----- // Why is here void ?

if (ListView3 != NULL)
{
TListItem *Item3= ListView3->Items->Add();
Item3->Caption = Text1;
}
}
}

Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: Help with csv and listview
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jul 6, 2017 9:28 AM   in response to: Thommy Ce in response to: Thommy Ce
El 06/07/2017 a las 15:50, Thommy Ce escribió:
Hello Antonio, can you explain me the Comparefunktion ? i dont get it exactly
I have 2(3) questions, i marked it with <---- //question
I hope u have the last patience to explaim me this :)
Thank You!

void __fastcall CompareData(
TListView *ListView1, int Column1,
TListView *ListView2, int Column2,
TListView *ListView3)
{
TListItems *List1 = ListView1->Items;
TListItems *List2 = ListView2->Items;

for (int Index1= 0, Index2= 0; Index1< List1->Count; ++Index1)
{
TListItem *Item1= List1->Item[Index1];
String Text1= Column1== 0 ? Item1->Caption :
Item1->SubItems->Strings[Column1-1]; <----- / / What happens here with Column1-1 ? and int Compare = -1 ?

The text which is shown in the first column (Column1 = 0) is Item1->Caption.
The text which is shown in the second column (Column1 = 1) is Item1->SubItems->Strings[0] <-- Column1-1 = 1-1 = 0.
The text which is shown in the third column (Column1 = 2) is Item1->SubItems->Strings[1] <-- Column1-1 = 2-1 = 1.
The text which is shown in the forth column (Column1 = 3) is Item1->SubItems->Strings[2] <-- Column1-1 = 3-1 = 2.
And so on..

int Compare= -1;

If Index2 >= List2->Count the while loop is not executed which means that Item1 (from ListView1) is not in ListView2.
When Compare is less than 0 (ex. -1) Item1 is added to ListView3 (Look at the conditional "if (Compare< 0)" after the
while loop.

while (Index2< List2->Count)
{
TListItem *Item2= List2->Item[Index2];
String Text2= Column2== 0 ? Item2->Caption :
Item2->SubItems->Strings[Column2-1]; <----- // so i think if u can explain this one above it should be logicly the same

Compare= Text1.Compare(Text2);
if (Compare< 0)
break;

Index2++;

if (Compare== 0)
break;
}

if (Compare< 0)
{
Item1->Data= (void*)1; <----- // Why is here void ?

It's a C-style typecast. The type of the Data property is void* so I typecast the integer value 1 to void*.
Using the C++ style the typecast would be like this:
    Item1->Data= reinterpret_cast<void*>(1);

That is used as a flag to show the item text in red color in the ListView's OnCustomDrawItem event.
If you don't need it, just remove that line.


if (ListView3 != NULL)
{
TListItem *Item3= ListView3->Items->Add();
Item3->Caption = Text1;
}
}
}
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02