5 Replies - 4001 Views - Last Post: 11 April 2010 - 05:05 AM Rate Topic: -----

#1 vkod  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 31-March 10

Replacing items in a listBox by doube click event

Posted 10 April 2010 - 04:40 PM

Plz I need help on how to write the code for replacing an Item in a listbox by double click event in vb.net.
I only know about using this code to add
ListBox1.Items.Add(TextBox1.Text)
TextBox1.Text = ""
item from textbox to listbox
But I need the to know how to write the code for replacing an item when the item is double click.
Thank you.

This post has been edited by vkod: 10 April 2010 - 04:44 PM

Is This A Good Question/Topic? 0
  • +

Replies To: Replacing items in a listBox by doube click event

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1533
  • View blog
  • Posts: 4,919
  • Joined: 25-September 09

Re: Replacing items in a listBox by doube click event

Posted 10 April 2010 - 06:36 PM

Since you didn't supply any code for us to help you with, I'll supply this much and you should be able to produce something off of it. Then if you get stuck, submit the code you have and we can help you better.

  Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
        ListBox1.Items(ListBox1.SelectedIndex) = "I'm Changed!"
    End Sub


Please enclose any code you submit inside the code tags this can be easily done by hilighting the code segment and clicking the <> on the toolbar
Was This Post Helpful? 0
  • +
  • -

#3 _HAWK_  Icon User is offline

  • Master(Of Foo)
  • member icon

Reputation: 1030
  • View blog
  • Posts: 4,011
  • Joined: 02-July 08

Re: Replacing items in a listBox by doube click event

Posted 10 April 2010 - 06:58 PM

Opps... I missed!!! :whistling:

This post has been edited by hawkvalley1: 10 April 2010 - 07:03 PM

Was This Post Helpful? 0
  • +
  • -

#4 vkod  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 31-March 10

Re: Replacing items in a listBox by doube click event

Posted 11 April 2010 - 01:16 AM

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim just(4, 2) As Integer
Dim row As Integer
Dim col As Integer
Dim vac As String()
vac = New String(just.GetUpperBound(0)) {}

ListBox1.Items.Clear()
For row = 0 To 4
For col = 0 To 2
'I am trying to create an argument here which will be if row is double click the user can 'change the status of the row such as Make a reservation or cancel a reservation. 'Otherwise the row is vacant. 
' I got stuck in doing it. Because I can only make the status constant here. Nothing change

vac(row) = "Vacant"


ListBox1.Items.Add(row & " " & col & " " & vac(row.ToString) & " ")

Next

Next



End Sub 


Thank you guys!
Here is what I am trying to do in a simple form.
To enable a user to change the status of the row either vacant or reserved by double clicking event.
any suggestion will be highly appreciated. you dont need to follow what I did but can suggestion to me how to go about doing.
Was This Post Helpful? 0
  • +
  • -

#5 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1533
  • View blog
  • Posts: 4,919
  • Joined: 25-September 09

Re: Replacing items in a listBox by doube click event

Posted 11 April 2010 - 04:28 AM

Try adding this, upon double click it stores the selecteditem to the string currItem and then checks to see if that string ends with the string "vacant ". If so, then we know that it needs to be changed to "reserved" so we use SubString to get all but the word vacant and append the word "reserved", if "vacant" does not appear then we use the same method to remove "reserved" and append "vacant".

So you end up with a sort of toggle, each double-click switches to the opposite setting.


    Private Sub ListBox1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
        Dim currItem As String = ListBox1.SelectedItem.ToString
        If currItem.ToLower.EndsWith("vacant ") Then
            ListBox1.Items(ListBox1.SelectedIndex) = currItem.ToString.Substring(0, currItem.Length - 7) & "Reserved "
        Else
            ListBox1.Items(ListBox1.SelectedIndex) = currItem.ToString.Substring(0, currItem.Length - 9) & "Vacant "
        End If
    End Sub

This post has been edited by CharlieMay: 11 April 2010 - 04:48 AM

Was This Post Helpful? 0
  • +
  • -

#6 vkod  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 31-March 10

Re: Replacing items in a listBox by doube click event

Posted 11 April 2010 - 05:05 AM

thank you charlieMay. I will try that as soon as possible and tell you how it goes.

I tried it & it worked out.
Kudos to CharlieMay

This post has been edited by vkod: 11 April 2010 - 05:47 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1