lstToSearch.Items.RemoveAt(lstToSearch.SelectedIndex);
Now in the "olden days" I would have to into events such as SelectionChange and have btnRemove.Enabled = True, but I'm sure there must be a more elegant way with data bindings? Am I right?
So to recap, when the user selects an item on the listbox, the remove button becomes enabled. When no item is selected the remove button is disabled
Thanks
Thomas

Mike GoldRank #50 · 30.6K reputationPosted Sep 11, 2010, 6:10 PM EDT
Then you can write the converter to choose true if there is a selectedItem selected and false if its not.
Satyapriya NayakRank #47 · 31.5K reputationPosted Sep 11, 2010, 9:02 PM EDT
Here is a solution :-
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
listBox1.Items.Add("a");
listBox1.Items.Add("b");
listBox1.Items.Add("c");
listBox1.Items.Add("d");
button1.Enabled = false;
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
visible();
}
void visible()
{
if (listBox1.Text == "")
{
button1.Enabled = false;
}
else
{
button1.Enabled = true;
}
}
private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.RemoveAt(listBox1.SelectedIndex);
visible();
}
}
}
Thanks
If it helps you plz mark it as Accepted answer