[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

reselect ListBox1

Posted on 2006-07-15
4
Medium Priority
?
320 Views
Last Modified: 2010-04-23
hello
how can I make a button
that clicks the selected
ListBox1.SelectedIndex

this one will go to the next one
ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1

this one will go to the one before
ListBox1.SelectedIndex = ListBox1.SelectedIndex - 1

but how do I make it to reselect the actula one?
0
Comment
Question by:aplelois
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 14

Expert Comment

by:Ramuncikas
ID: 17115146
Could you please clear out: you want to have three buttons where:
 - first would select a particular item in a listbox
 - second would select next item in a listbox
 - third would select previuos item in a listbox

Is that correct?
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 17115161
Hi aplelois;

May be I am missing something but the ListBox SelectedIndex always points to the currently selected list box item. So when you do ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1 it will selected the next item in the list box, al long as there is one otherwise you will get an out of range error. and the same holeds true for ListBox1.SelectedIndex = ListBox1.SelectedIndex - 1. The only time that SelectedIndex is not pointing to one of the Items is when SelectedIndex is -1.

So can you explaine your question please?

Fernando
0
 
LVL 13

Accepted Solution

by:
iHadi earned 2000 total points
ID: 17115844
Hi aplelois
What I understood from your question is that you want to reselect a selected item in a listbox via a button to reraise the ListBox_SelectedIndexChanged event. To acheive this the easiest way put the code you want to execute in the event in a seprate sub and call it from the event handler and from the button. The following code demonstrates the previous: Add a listbox and a button to a form and past the folowing code:


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim i As Integer
        Button1.Text = "Current"
        Button2.Text = "Previous"
        Button3.Text = "Next"

        For i = 1 To 10
            ListBox1.Items.Add(i)
        Next
    End Sub

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

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Listbox1Event()
    End Sub

    Private Sub Listbox1Event()
        Try
            MessageBox.Show(ListBox1.SelectedItem.ToString)
        Catch

        End Try
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Try
            ListBox1.SelectedIndex = ListBox1.SelectedIndex - 1
        Catch

        End Try
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Try
            ListBox1.SelectedIndex = ListBox1.SelectedIndex + 1
        Catch

        End Try
    End Sub

0
 

Author Comment

by:aplelois
ID: 17115893
I have that if you click on the selected index you go to a page
I want so that if something happens just click that selected index
how can I do that?
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question