Click here to Skip to main content
15,918,050 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
i want to open a particular file on click of item in List box..thanks...
Posted
Comments
Sandeep Mewara 14-Apr-11 1:40am    
Did you try? It's simple and straight forward.

I would suggest you to do it on DoubleClick.

Do something like,
C#
switch (ListBox1.SelectedIndex) 
{
	case 0:
		//open file 1
		//Process.Start("notepad");
		break;
	case 1:
		//open file 2
		//Process.Start("calc");
		break;
	default:
		break;
	//do nothing
}
 
Share this answer
 
Comments
girish sp 14-Apr-11 7:08am    
double click is good option to go..my 5
Do it like this :

As said by Prerak, do the below in a DoubleClick event.

Add this to your constructor :
C#
listBox2.MouseDoubleClick += new MouseButtonEventHandler(listBox2_MouseDoubleClick);

This is the function to implement it:
C#
void listBox2_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
    ListBoxItem item =(ListBoxItem)listBox2.SelectedItem;
    Process.Start(item.Content.ToString());
}
 
Share this answer
 
v2
Comments
girish sp 14-Apr-11 7:09am    
my 5!!
Tarun.K.S 14-Apr-11 7:22am    
Thanks girish, well appreciated!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900