2 Replies - 447 Views - Last Post: 08 February 2013 - 01:18 AM Rate Topic: -----

#1 jayveeeeeeeeeeeeeeeeeeee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 06-February 13

double click listbox

Posted 07 February 2013 - 07:55 AM

i wanted to do is when i double click item in listbox then the region will display in textbox ...please help me for my assignment ..can anyone can give me idea how to do it..
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.BackColor = Color.Chocolate
        Label1.ForeColor = Color.Blue
        Label1.Font = New Font(Font.Name, 12, FontStyle.Regular)
        Label2.ForeColor = Color.Blue
        Label2.Font = New Font(Font.Name, 12, FontStyle.Regular)
        '   ListBox1.Text = "Province"
        ListBox1.Items.Add("Isabela")
        ListBox1.Items.Add("Tarlac")
        ListBox1.Items.Add("Bulacan")
        ListBox1.Items.Add("Cebu")
        ListBox1.Items.Add("Bohol")
        ListBox1.Items.Add("Negros")
        ListBox1.Items.Add("Davao")
        ListBox1.Items.Add("Cotobato")
        ListBox1.Items.Add("Zamboanga")
        ListBox1.ForeColor = Color.Blue
        Label3.Text = "Province:"
        Label3.Font = New Font(Font.Name, 12, FontStyle.Regular)
        Label3.ForeColor = Color.Blue
        Label4.Text = "Isabela"
        Label4.Font = New Font(Font.Name, 12, FontStyle.Regular)
        Label4.ForeColor = Color.Blue
        Label5.Text = "Tarlac"
        Label5.Font = New Font(Font.Name, 12, FontStyle.Regular)
        Label5.ForeColor = Color.Blue
        Label6.Text = "Bulacan"
        Label6.Font = New Font(Font.Name, 12, FontStyle.Regular)
        Label6.ForeColor = Color.Blue
        Label7.Text = "Cebu"
        Label7.Font = New Font(Font.Name, 12, FontStyle.Regular)
        Label7.ForeColor = Color.Blue
        Label8.Text = "Bohol"
        Label8.Font = New Font(Font.Name, 12, FontStyle.Regular)
        Label8.ForeColor = Color.Blue
        Label9.Text = "Negros"
        Label9.Font = New Font(Font.Name, 12, FontStyle.Regular)
        Label9.ForeColor = Color.Blue
        Label10.Text = "Davao"
        Label10.Font = New Font(Font.Name, 12, FontStyle.Regular)
        Label10.ForeColor = Color.Blue
        Label11.Text = "Cotobato"
        Label11.Font = New Font(Font.Name, 12, FontStyle.Regular)
        Label11.ForeColor = Color.Blue
        Label12.Text = "Zamboanga"
        Label12.Font = New Font(Font.Name, 12, FontStyle.Regular)
        Label12.ForeColor = Color.Blue


        '  ListBox1.SetSelected(2, True)
        '   ListBox1.SetSelected(4, True)
        '   ListBox1.SetSelected(8, True)
        ' ;   ListBox1.SetSelected(10, True)
  

            ' & " Is On NCR Region"
        ' ListBox1.Items.Add(TextBox1.Text)
        '  End If
        'NCR REGION:
        'isabela.tarlac,bulacan
        'Visayan Region
        'cebu,bohol,negros
        'mindanao region 
        'davao,cotobato,zamboanga

    End Sub

    
    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
  
    End Sub


    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        If ListBox1.SelectedItem = "Tarlac" Then
            TextBox1.Text = "Tarlac Is Ncr Region"
            Label5.BackColor = Color.White
        End If


        '  TextBox1.Text = "Here are the selected items: "&  & " "

    End Sub
End Class


file:///C:/Users/buddah15/Documents/3.png

thanks in advanced

Is This A Good Question/Topic? 0
  • +

Replies To: double click listbox

#2 C.Andrews  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 14
  • View blog
  • Posts: 166
  • Joined: 18-October 12

Re: double click listbox

Posted 07 February 2013 - 08:11 AM

I do this in one of my programs:

Private Sub lstAvailable_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstAvailable.DoubleClick
        Dim selectedItems = (From i In lstAvailable.SelectedItems).ToArray()
        For Each selectedItem In selectedItems
            lstSelected.Items.Add(selectedItem)
            lstAvailable.Items.Remove(selectedItem)
        Next
    End Sub




This removes the item (or items, since mine is multiselect) from one listbox and adds it to another, but if you want to move from a listbox to another type of control, it's basically the same thing, just use the appropriate method for adding the item to the destination in place of:

            lstSelected.Items.Add(selectedItem)



You can also add additional code in to preserve the source formatting if that's what you want. Cheers

-C

This post has been edited by C.Andrews: 07 February 2013 - 08:13 AM

Was This Post Helpful? 0
  • +
  • -

#3 jayveeeeeeeeeeeeeeeeeeee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 06-February 13

Re: double click listbox

Posted 08 February 2013 - 01:18 AM

thanks i did it....thanks for the reply and time and for your idea;
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1