2 Replies - 470 Views - Last Post: 15 January 2013 - 05:10 AM Rate Topic: -----

#1 jayvincentmcruz  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 03-October 12

help me

Posted 15 January 2013 - 03:40 AM

 Public Class Form1

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

        Dim d As Integer
        ListBox1.BeginUpdate()

        For d = 1 To 5
            ListBox1.Items.Add("" & d.ToString())

            ListBox2.EndUpdate()
        Next d
    End Sub
End Class





can anyone help me .. i am doing loop in listbox1 and to multiply by itself .first the listbox1 is loop in to 1 to 5 and when i click the button the listbox1 is going to listbox2 but it's multiply by itself......my problem when i run my program the listbox1 is empty i dont know why and anyone can give an idea how to multiply the loop by itself

Is This A Good Question/Topic? 0
  • +

Replies To: help me

#2 kai_itz me  Icon User is offline

  • D.I.C Head

Reputation: 28
  • View blog
  • Posts: 159
  • Joined: 03-August 12

Re: help me

Posted 15 January 2013 - 04:16 AM

THIS WILL ADD ITEMS TO LISTBOX1


    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        ListBox1.BeginUpdate()
        ' Loop through and add 5 items to the ListBox. 
        Dim x As Integer
        For x = 1 To 5
            ListBox1.Items.Add("" & x.ToString())
        Next x
        ' Allow the ListBox to repaint and display the new items.
        ListBox1.EndUpdate()

        ' Select three items from the ListBox.
        ListBox1.SetSelected(0, True)
        ListBox1.SetSelected(1, True)
        ListBox1.SetSelected(2, True)
        ListBox1.SetSelected(3, True)
        ListBox1.SetSelected(4, True)

    End Sub




THIS WILL COPY DATA FROM LISTBOX1 TO LISTBOX2 AS MULTIPLE OF ITSELF SO OUTPUT IN LISTBOX2 WILL BE (1 4 9 16 25)

IN ORDER TO COPY DATA YOU HAVE TO SELECT DATA AFTER THAT PRESS SPECIFIED BUTTON(SAY BUTTON4 IN THIS).. YOU CAN ALSO SET MULTISELECT OPTION TO TRUE.

 Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        For Each item As Integer In ListBox1.SelectedItems
            ListBox2.Items.Add((item) * (item))
        Next
    End Sub


This post has been edited by kai_itz me: 15 January 2013 - 04:19 AM

Was This Post Helpful? 0
  • +
  • -

#3 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3075
  • View blog
  • Posts: 10,277
  • Joined: 12-December 12

Re: help me

Posted 15 January 2013 - 05:10 AM

The Begin/EndUpdate should apply to ListBox2. Or, at least, to the same ListBox;
The EndUpdate only needs to occur once, after the list is built;
List items (and most everything else in VB) are indexed from 0, not 1.

I'm assuming you are looking for something like this:

        Dim d As Integer
        ListBox2.BeginUpdate()

        For d = 0 To 4      'items are indexed from 0
            ListBox2.Items.Add((Val(ListBox1.Items(d)) * Val(ListBox1.Items(d))).ToString())
        Next d
        ListBox2.EndUpdate()


Well, I'm not certain what you are trying to do(?). But the reason ListBox1 is empty is that your current code begins updating but doesn't end the updating.

Isn't this VB.NET rather than VB6??

This post has been edited by andrewsw: 15 January 2013 - 05:19 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1