Avatar of sammySeltzer
sammySeltzer
Flag for United States of America asked on

Data organization issue

Greetings again mates.

When I run the following code:

If dtCurrentTable.Rows.Count > 0 Then
                '//Next collection. Spouse Information
                For Each row As DataRow In dtCurrentTable.Rows

                    Dim txtsourcen As String = TryCast(row.ItemArray(1), String)
                    Dim txtsourcea As String = TryCast(row.ItemArray(2), String)
                    Dim txtsourcei As String = TryCast(row.ItemArray(3), String)


                    lblPreviewSourceName.Text += txtsourcen & "<br />"
                    lblPreviewSourceAddress.Text += txtsourcea & "<br />"
                    lblPreviewIncomeSource.Text += txtsourcei & "<br />"


                    'get the values from the TextBoxes

                    'then add it to the collections with a comma "," as the delimited values

                    sc.Add(lblPreviewSourceName.Text + "," + lblPreviewSourceAddress.Text + "," + lblPreviewIncomeSource.Text)
                    rowIndex += 1
                Next

Open in new window

, I get this result and the way it is presented.

Name: Ivory West
Indiana Jones

Address: 20 Ivory Street
65 Kay Dr

Income: 1000001
5820000 

Open in new window


I am getting that result because we are dynamically creating rows. In this case, there are two rows relating to same field names.

I would like the data to be presented in the following format:

Name: Ivory West
Address: 20 Ivory Street
Income: 1000001

Name: Indiana Jones
Address: 65 Kay Dr
Income: 5820000 

Open in new window


What do I need to change in the code I posted to get this type of lay out?

Thank you.
ASP.NETVisual Basic.NET* DataGridView.NET Programming

Avatar of undefined
Last Comment
sammySeltzer

8/22/2022 - Mon
Ryan Chong

the existing labels are printing the data at property level (like: Name, Address, Income) and now you want to print the data at record level (group those properties together).

hence, you may just need to use one label with this code: (not really tested, you may customize accordingly)

			If dtCurrentTable.Rows.Count > 0 Then
                '//Next collection. Spouse Information
				
				Dim output As String = "";
				lblPreviewSourceName.Text = ""
				
                For Each row As DataRow In dtCurrentTable.Rows

                    Dim txtsourcen As String = TryCast(row.ItemArray(1), String)
                    Dim txtsourcea As String = TryCast(row.ItemArray(2), String)
                    Dim txtsourcei As String = TryCast(row.ItemArray(3), String)
					
                    output = "Name: " & txtsourcen & "<br />Address: " & txtsourcea & "<br />Income: " & txtsourcei & "<br />"
					
                    lblPreviewSourceName.Text += output & "<br />"

                    sc.Add(lblPreviewSourceName.Text + "," + lblPreviewSourceAddress.Text + "," + lblPreviewIncomeSource.Text)
                    rowIndex += 1
                Next
			End If	

Open in new window

sammySeltzer

ASKER
Thank you Ryan.

It is very close to the solution I am looking for.

Please see screenshot of what I am getting.

I have circled the one little issue to need to be addressed.

The results is what I am looking for but it leaves an extra Address and Income text.
needre.png
Ryan Chong

i believe what you highlighted was generated by label controls: lblPreviewSourceAddress and lblPreviewIncomeSource.

you can try to set its value to "" or directly remove it if they're unused.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
sammySeltzer

ASKER
I believe you meant this line:

 sc.Add(lblPreviewSourceName.Text + "," + lblPreviewSourceAddress.Text + "," + lblPreviewIncomeSource.Text)

Open in new window


I was thinking the same thing and so I removed them and changed that line to this:

                 
  sc.Add(lblPreviewSourceName.Text)

Open in new window


but they are still there. That's why I posted back because I am not sure what else could be causing.
ASKER CERTIFIED SOLUTION
Ryan Chong

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
sammySeltzer

ASKER
I removed those from the HTML markup and seems good enough; just some cosmetic stuff that I will work out.

Thank you for your help.
sammySeltzer

ASKER
Thank you
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.