Rick Becker
asked on
How do I output data from ListView Control with fields not in same order (or as many) as the ListView Hearder
OK Greetings..
I have done some searching and I have not quite found the answer to my issue so I guess I will ask the question here. (I'll include code snippets)
(1) I use Visual Studio 2017 express
(2) I Use Visual Basic .NET
(3) I am creating a Windows Application
OK.. I have a ListView Control contained with a TabControl on a Form... The ListView has a Header of 40 fields and I can populate as many rows as I desire each with 40 fields of data.. (all working).
I need to get each row from the list and output that row data to a .TXT file but NOT All of the fields of data and NOT in the same order as represented in the ListView Header.
I actually have most all of this working EXCEPT my code will output a Duplicate record for the number of records within the ListView control.. Example if I have 3 rows of data and a header record it will successfully output the desired number of data fields in the desired order for the first row of data then it will REPEAT/DUPLICATE that row of data for the number of rows in the ListView Control and then one more for the Header row.. ie 4 in the current example..
The following code snippet is what I currently have and need a bit of help. Please note that I load the Header field names into an Array and then use that array
to INDEX into the ROW Item data.
BTW I hope that this is the right way to ask and or present questions to EE.. If not please let me know.
Thanks in advance.
Rick
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- --------
'######################### ########## ########## ########## ########## #########
'Loop through the ListView Header values and store them in an array that
' is later used as a way to index the Header Name and Value associated
' with that column header
'######################### ########## ########## ########## ########## ########
ListViewFieldNameString = ""
For IntI = 0 To StandardUPCQueryTable.Colu mns.Count - 1
ListViewFieldNameString = ListViewFieldNameString & StandardUPCQueryTable.Colu mns(IntI). Text.ToStr ing & "|"
Next
ListViewFieldNameArray = Split(ListViewFieldNameStr ing, "|")
'######################### ########## ########## ########## ########## ########## ####
' Now loop through the ListView data rows and select the required field data to
' build the listing file. Output each New listing on a separate line in the
' Newly create Listing file.
'######################### ########## ########## ########## ########## ########## ######
MsgBox("Grid has " & StandardUPCQueryTable.Item s.Count.To String & "lines")
For Each item As ListViewItem In StandardUPCQueryTable.Item s
'Action(SiteID=US|Country= US|Currenc y=USD|Vers ion=403|CC =UTF-8) field
objWriter.Write("Add" & vbTab)
'Product:ProductReferenceI D - fiels
FieldIndex = GetIndexFromArray(ListView FieldNameA rray, "ReferenceID")
objWriter.Write(StandardUP CQueryTabl e.Items(1) .SubItems. Item(Field Index).Tex t.ToString & vbTab) 'this line worked
'Product:IncludePreFilledI temInforma tion - field
objWriter.Write("1" & vbTab)
'Product:IncludeStockPhoto URL - field
objWriter.Write("1" & vbTab)
'CustomLabel - field - our SKU
FieldIndex = GetIndexFromArray(ListView FieldNameA rray, "CustomLabel")
objWriter.Write(StandardUP CQueryTabl e.Items(1) .SubItems. Item(Field Index).Tex t.ToString & vbTab)
'ConditionID - field
FieldIndex = GetIndexFromArray(ListView FieldNameA rray, "ConditionID")
ConditionIDString = StandardUPCQueryTable.Item s(1).SubIt ems.Item(F ieldIndex) .Text.ToSt ring
objWriter.Write(GetConditi onIDCode(C onditionID String).To String & vbTab)
'ConditionDescription - field
FieldIndex = GetIndexFromArray(ListView FieldNameA rray, "ConditionDescription")
objWriter.Write(StandardUP CQueryTabl e.Items(1) .SubItems. Item(Field Index).Tex t.ToString & vbTab)
'Binding/Category - field
FieldIndex = GetIndexFromArray(ListView FieldNameA rray, "Category")
MediaBidingString = StandardUPCQueryTable.Item s(1).SubIt ems.Item(F ieldIndex) .Text.ToSt ring
objWriter.Write(GetMediaBi ndingIdCod e(MediaBid ingString) .ToString & vbTab)
objWriter.Write(vbNewLine)
Next
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -------
I have done some searching and I have not quite found the answer to my issue so I guess I will ask the question here. (I'll include code snippets)
(1) I use Visual Studio 2017 express
(2) I Use Visual Basic .NET
(3) I am creating a Windows Application
OK.. I have a ListView Control contained with a TabControl on a Form... The ListView has a Header of 40 fields and I can populate as many rows as I desire each with 40 fields of data.. (all working).
I need to get each row from the list and output that row data to a .TXT file but NOT All of the fields of data and NOT in the same order as represented in the ListView Header.
I actually have most all of this working EXCEPT my code will output a Duplicate record for the number of records within the ListView control.. Example if I have 3 rows of data and a header record it will successfully output the desired number of data fields in the desired order for the first row of data then it will REPEAT/DUPLICATE that row of data for the number of rows in the ListView Control and then one more for the Header row.. ie 4 in the current example..
The following code snippet is what I currently have and need a bit of help. Please note that I load the Header field names into an Array and then use that array
to INDEX into the ROW Item data.
BTW I hope that this is the right way to ask and or present questions to EE.. If not please let me know.
Thanks in advance.
Rick
--------------------------
'#########################
'Loop through the ListView Header values and store them in an array that
' is later used as a way to index the Header Name and Value associated
' with that column header
'#########################
ListViewFieldNameString = ""
For IntI = 0 To StandardUPCQueryTable.Colu
ListViewFieldNameString = ListViewFieldNameString & StandardUPCQueryTable.Colu
Next
ListViewFieldNameArray = Split(ListViewFieldNameStr
'#########################
' Now loop through the ListView data rows and select the required field data to
' build the listing file. Output each New listing on a separate line in the
' Newly create Listing file.
'#########################
MsgBox("Grid has " & StandardUPCQueryTable.Item
For Each item As ListViewItem In StandardUPCQueryTable.Item
'Action(SiteID=US|Country=
objWriter.Write("Add" & vbTab)
'Product:ProductReferenceI
FieldIndex = GetIndexFromArray(ListView
objWriter.Write(StandardUP
'Product:IncludePreFilledI
objWriter.Write("1" & vbTab)
'Product:IncludeStockPhoto
objWriter.Write("1" & vbTab)
'CustomLabel - field - our SKU
FieldIndex = GetIndexFromArray(ListView
objWriter.Write(StandardUP
'ConditionID - field
FieldIndex = GetIndexFromArray(ListView
ConditionIDString = StandardUPCQueryTable.Item
objWriter.Write(GetConditi
'ConditionDescription - field
FieldIndex = GetIndexFromArray(ListView
objWriter.Write(StandardUP
'Binding/Category - field
FieldIndex = GetIndexFromArray(ListView
MediaBidingString = StandardUPCQueryTable.Item
objWriter.Write(GetMediaBi
objWriter.Write(vbNewLine)
Next
--------------------------
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
--------------------------
Open in new window