new to vb, list box & dada grid view help

J

jcoon

All,

I'm new to VB, I'm trying to load data into two colunms of a list box
or datagrid. I'm not sure how to get my data into the second colunms of the
list box and If I can post this type of data into a data grid view. any
suggestions are welome. also, can headers be added to a list box?

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim elevDsection As Double

elevDsection = 150

Dim strFormat As String

strFormat = "#0.00"

Dim slope As Double

Dim samplestartdist As Double

Dim sampledist As Double

Dim rwoffset As Double

Dim offsetelevdist As Double

Dim offsetelev As Double

slope = 1 / 34

offsetelevdist = 100

offsetelev = (slope * offsetelevdist) + elevDsection

samplestartdist = 0

sampledist = 500 + offsetelevdist

rwoffset = 0

rwoffset = rwoffset

Me.ListBox1.FormattingEnabled = True

Me.ListBox1.HorizontalScrollbar = False

Do While sampledist > 0

ListBox1.Items.Add(rwoffset)

rwoffset = rwoffset + offsetelevdist

sampledist = sampledist - offsetelevdist

offsetelev = (slope * rwoffset) + elevDsection

Loop

end sub
 
M

MBUnit

jcoon said:
All,

I'm new to VB, I'm trying to load data into two colunms of a list box
or datagrid. I'm not sure how to get my data into the second colunms of the
list box and If I can post this type of data into a data grid view. any
suggestions are welome. also, can headers be added to a list box?


Use a Datatable and bind the aTable to Listbox.Datasource = aTable or
do it with a datagrid.

http://www.dotnetspider.com/resources/19418-DataTable-C.aspx

Use this to convert the C# code over to VB.

http://www.developerfusion.com/tools/convert/csharp-to-vb/
 
C

Cor Ligthert[MVP]

jcoon,

Be aware that a list box has no second column. There is an option to show a
listbox vertical, but that is no second column.

For the rest it is simple
x.DataSource = datatable
and then with a listbox
x.DataMember = "column1"
x.DisplayMember = "column2"

Cor
 
J

jcoon

MBUnit,

Thank you, I'll try to follow your provided sample. I was able to convert
the C sample
Have a great day,
John
 

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