cygnusx

I have a panel with listbox in it.In the panel there are and few other panels.When SelectedIndexChanged event is raised i want to show the appropriate panel.

for example:

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
switch (listBox1.SelectedIndex.ToString())
{
case "0":
//show panel1
break;
case "1":
//show panel2
break;

//and so on
}
}

How to do that


Re: Windows Forms General ListBox SelectedIndexChanged event

Bob zhu - MSFT

Hi see my code, it works well on my PC

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

namespace CS2

{

public partial class Form2 : Form

{

public Form2()

{

InitializeComponent();

}

private void Form2_Load(object sender, EventArgs e)

{

this.MyLoad();

}

private void MyLoad()

{

this.listBox1.Items.Add("Panel a");

this.listBox1.Items.Add("Panel b");

panel1.Visible = false;

panel2.Visible = false;

this.listBox1.SelectedIndexChanged += new EventHandler(listBox1_SelectedIndexChanged);

}

void listBox1_SelectedIndexChanged(object sender, EventArgs e)

{

switch (listBox1.SelectedIndex.ToString())

{

case "0":

{

panel1.Visible = true;

panel2.Visible = false;

break;

}

case "1":

{

panel2.Visible = true;

panel1.Visible = false;

break;

}

default:

{

panel2.Visible = false;

panel1.Visible = false;

break;

}

}

}

}

}






Re: Windows Forms General ListBox SelectedIndexChanged event

cygnusx

Thanks!