Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ListBox issue in VB2010

Status
Not open for further replies.

RanbeerSingh

Programmer
Aug 6, 2015
3
0
0
IN
Hi All

I am using a listbox and want to display a variable arrays value in listbox.

Code:
Public InputHistorypoint(256), Perameter(0-600) As String
Dim b as integer
Public addrs, InputNO as integer


    For b = 0 To InputNO - 1
        InputHistorypoint(b) = Perameter((addrs + 4) + b)
        lstHistoryPoint.Items.Add(InputHistorypoint(b))
    Next

Please see the attachment
It display: -

ListViewItem:{Input-1}

ListViewItem:{Input-2}

ListViewItem:{Input-3}

ListViewItem:{Input-4}

ListViewItem:{Input-5}

ListViewItem:{Input-6}

Actual value of variable are under {}. It's Displaying "ListViewItem:" extra text. I think it's property configuration mistake.

Please help me
 
 http://files.engineering.com/getfile.aspx?folder=dee48200-84d2-457d-8c6e-2c6cdf687695&file=ListBox.png
In some places (at work) we cannot download attached file.

What are you passing in the array named [tt]Perameter[/tt]?
Could you give an example of what's in it?
And what you expect to see in the [tt]lstHistoryPoint[/tt] listbox?

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
1,2.

Variable 'Perameter' is a Public variable. When I open a file total values saves in 'Perameter'(array).

Perameter(0) = "Input-1"
Perameter(1) = "Input-2"
Perameter(2) = "Input-3"
Perameter(3) = "Input-4"
Perameter(4) = "Input-5"
Perameter(5) = "Input-6"

Code:
InputHistorypoint(b) = Perameter((addrs + 4) + b)
I am saving 'Perameter' arrays value in 'InputHistorypoint' arrays

Code:
lstHistoryPoint.Items.Add(InputHistorypoint(b))
and adding in listbox 'lstHistoryPoint'

3.
I want to see: -

Input-1
Input-2
Input-3
Input-4
Input-5
Input-6


But It's sowing: -

ListViewItem:{Input-1}
ListViewItem:{Input-2}
ListViewItem:{Input-3}
ListViewItem:{Input-4}
ListViewItem:{Input-5}
ListViewItem:{Input-6}

Adding "ListViewItem:{}" extra text .
 
This will give you what you want (I hope):

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

        Dim Perameter(0 To 600) As String

        Perameter(0) = "Input-1"
        Perameter(1) = "Input-2"
        Perameter(2) = "Input-3"
        Perameter(3) = "Input-4"
        Perameter(4) = "Input-5"
        Perameter(5) = "Input-6"

        With lstHistoryPoint
            .Items.Clear()
            For i = 0 To Perameter.Length - 1
                If Len(Perameter(i)) > 0 Then
                    .Items.Add(Perameter(i))
                End If
            Next i
        End With

    End Sub

"I am saving 'Perameter' arrays value in 'InputHistorypoint' arrays"
Why?
Personally I don’t like to 'juggle' data between different data storage.

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
I'm sorry It was my mistake. When I was putting data in 'Perameter' variable. I was using

Code:
Perameter(i) = lstPoints.Items(i).ToString

I change it with

Code:
Perameter(i) = lstPoints.Items(i).SubItems(0).Text

It's working fine
Thank you for your valuable advices.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top