Hi i m new in c#.
i want to my button enable when i select any item in list box.
i m able to do it but when i deselect all the items in listbox so my button is still enable.i want to disable now when no item is selected in list box..
Regards...
Farhad Idrees

Recommended Answers

private void listBox1_SelectedIndexChanged(object sender, EventArgs e) {
    if (listBox1.SelectedIndices.Count > 0) {
        button1.Enabled = true;
    } else {
        button1.Enabled = false;
    }
}
Jump to Post

All 2 Replies

private void listBox1_SelectedIndexChanged(object sender, EventArgs e) {
    if (listBox1.SelectedIndices.Count > 0) {
        button1.Enabled = true;
    } else {
        button1.Enabled = false;
    }
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e) {
    if (listBox1.SelectedIndices.Count > 0) {
        button1.Enabled = true;
    } else {
        button1.Enabled = false;
    }
}

thanks man it's working well

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.