Export Data to Spreadsheet

G

Guest

I have data that I need to either put in a spreadsheet, or use in a listview to view it. I would rather use the listview but I don't understand how to put my data into it. Here is the code I have, currently I am just display all the data in a label and it sucks.
Private Sub btnGetDoubles_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesbtnGetDoubles.Click
Dim colors(9) As String
Dim duoColorCollection As New Collection
Dim nameList As String = ""
Dim oneInst As Class1
Dim intCounter As Integer

Dim i As Integer
Dim j As Integer
colors(0) = "Red"
colors(1) = "Green"
colors(2) = "Blue"
colors(3) = "Purple"
colors(4) = "White"
colors(5) = "Yellow"
colors(6) = "Brown"
colors(7) = "Orange"
colors(8) = "Black"
colors(9) = "Maroon"

Dim inst As New Class1

For i = 0 To colors.Length - 2
For j = i + 1 To colors.Length - 1
duoColorCollection.Add(colors(i) + "-" + colors(j))
inst.InstanceName = colors(i) + "-" + colors(j)
Next j
Next i

For Each inst.InstanceName In duoColorCollection ' Create list of names.
nameList &= inst.InstanceName & ControlChars.CrLf
Next

' Display the list of names in a label.
lblDoubles.Text = nameList
End Sub
 
C

Cor

Hi Optik,

I see only one column, why not a listbox.
Than it is very easy when you use a datatabel.

But before I type it, has it to be one column?

Cor
I have data that I need to either put in a spreadsheet, or use in a
listview to view it. I would rather use the listview but I don't understand
how to put my data into it. Here is the code I have, currently I am just
display all the data in a label and it sucks.
Private Sub btnGetDoubles_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) HandlesbtnGetDoubles.Click
 
K

Ken Tucker [MVP]

Hi,

You can databind to a collection. You can show any property
contained in a class. Try this.

Dim colors(9) As String

Dim duoColorCollection As New Collection

Dim nameList As String = ""

Dim oneInst As Class1

Dim intCounter As Integer

Dim i As Integer

Dim j As Integer

colors(0) = "Red"

colors(1) = "Green"

colors(2) = "Blue"

colors(3) = "Purple"

colors(4) = "White"

colors(5) = "Yellow"

colors(6) = "Brown"

colors(7) = "Orange"

colors(8) = "Black"

colors(9) = "Maroon"



For i = 0 To colors.Length - 2

For j = i + 1 To colors.Length - 1

Dim inst As New class1

inst.InstanceName = colors(i) + "-" + colors(j)

duoColorCollection.Add(inst)

Next j

Next i

ListBox1.DataSource = duoColorCollection

ListBox1.DisplayMember = "InstanceName"



The class

Public Class class1

Dim m_strName As String



Public Property InstanceName() As String

Get

Return m_strName

End Get

Set(ByVal Value As String)

m_strName = Value

End Set

End Property

End Class



Ken

-----------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top