School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
You're Browsing As A Guest! Register Now...
Become an Expert!

Join 357,971 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,549 people online right now.Registration is fast and FREE... Join Now!



Replacing List item in a list

52 Weeks of Code Challenge: Android

Week #11 of the 52 Weeks of Code Challenge is Android, you should give it a shot. Click Here!

Replacing List item in a list Rate Topic: -----

#1 KG87  Icon User is offline

  • D.I.C Head
  • PipPip

Reputation: 2
  • View blog
  • Posts: 52
  • Joined: 25-September 07


Dream Kudos: 0

Posted 09 February 2008 - 09:42 AM

ok bit of a noob question.

I have 2 listboxes, a command button and a textbox in a form.

for "training" purposes, both list boxes are filled with the numbers 1 - 10.

I wish to change the value of one of the items in the listbox and replace it with the value of the text box.

The code i've produced below doesnt work as expected.

the msgbox displays the listindex which is correct
the item is removed from the listindex which is also correct.

however, when the value of the textbox or "none" is added back into the listbox, the item is added at the bottom of the list instead of the place where the 1st item was removed.

Private Sub CommandButton1_Click()
Dim lnx As Integer
Dim plc As String

MsgBox ListBox2.ListIndex

lnx = ListBox2.ListIndex

ListBox2.RemoveItem ListBox2.ListIndex



If TextBox1.Text = "" Then

plc = "None"

ListBox2.AddItem plc
ListBox2.ListIndex = lnx

Else

ListBox2.ListIndex = lnx
ListBox2.AddItem TextBox1.Text


End If
 


Thanks in advance KG87
Was This Post Helpful? 0
  • +
  • -


#2 ahmad_511  Icon User is offline

  • MSX
  • Icon

Reputation: 51
  • View blog
  • Posts: 574
  • Joined: 28-April 07


Dream Kudos: 500

Re: Replacing List item in a list

Posted 10 February 2008 - 03:54 AM

Hello there
there are two ways to do that
1- use lndx when you add the list item
ListBox2.AddItem plc,lndx



2- don't remove the list item just change it like this
ListBox2.list(lndx)=TextBox2.text



It has been a while since I used vb6 so I hope I didn't missed somthing here
Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month