urgent !!!!listbox inserting problem

hi everyone,

I have a problem with manually inserting element into my listbox. There is the code I'm using:

ListBox2.Items.Insert(0, ListBox1.SelectedItem)

or

Dim myItem = New ListItem

myItem.value = "wisconsin"

myItem.text = "Wisconsin"

ListBox1.Items.Add(myItem)

I've also tried using the add method but either way I do it it still insert the element twice in the listbox. Now I dont know if there is something I'm doing wrong or is that a bug.

I'm using visual dev express 05 on windows xp pro.

thk you.



Answer this question

urgent !!!!listbox inserting problem

  • Chris R Jones

    But did you set a breakpoint and check F9 sets a breakpoint in your code, the code will stop there during execution in the IDE.

  • mjn

    If your code is only called once, and the item is being inserted twice, then it was already in there to start with, or other code is doing the insert. There is no bug where calling insert once causes an item to be inserted twice.



  • TheViewMaster

    Have you put a breakpoint in the code I'd be willing to bet that the problem is that your code is being called twice, probably as some event fires.



  • Canderson

    Perhaps you need to post the code, so we can see what you're doing Is the insert happening in response to a click event



  • David_Wilson

    Yes everyone my problem is solved.
    The way I did it is that in the button tag I had a onCLick that I replace by a onClientClick and its stopped firing twice but I still dont understand what is the difference and why the first method made it fire twice.

    And I'm gonna ask another question , does anyone know how to get the element from a listbox but not the selected one, any element without the element beeing selected


    Thank you Christian you put me in the path for that solution.

  • wramos

    hi,

    Is your problem solved

    Thank you,
    Bhanu.



  • Nate

    No I've tought about that and I removed the loop so I just tried it once and its still displaying 2 element in the listbox.
  • Ronald S.

    I've tried the breakpoint and unfortunately I have the same result.

    Do you think it could be something else beside the loop.


  • Art Gardner

    Protected Sub searchB_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles searchB.Click

    'Dim fn As String = TextBox1.Text

    'Dim ln As String = TextBox2.Text

    Dim myItem = New ListItem

    myItem.value = "wisconsin"

    myItem.text = "Wisconsin"

    ListBox1.Items.Add(myItem)

    'If (fn <> "" And ln <> "") Then

    'search_fn_ln(fn, ln)

    'Label1.Text = "fn and ln full"

    'ElseIf (ln <> "") Then

    'Label1.Text = "ln only full"

    'ElseIf (fn <> "") Then

    'Label1.Text = "fn only full"

    'Else

    'Label1.Text = "None full"

    'End If

    End Sub

    there is the code, its suppose to add wisconsin when the user click on a button.


  • WorkTimer

    My first guess is still that the event is being attached to the button twice, and so firing twice. Beyond that, I can't imagine what could cause it. But then your breakpoint would fire twice.



  • meade

    Thats the part I dont understand because that part is just a test so I tried to insert an element in the listbox so there is no loop and I not calling the insert anywhere else but I've tried everything and still getiing the inserting or displaying twice prob.
  • urgent !!!!listbox inserting problem