Error :
Unable to cast object of type ‘System.String’ to type ‘System.Windows.Forms.ListBox’.
private void button3_Click(object sender, EventArgs e)
{
foreach (ListBox item in SelectTables_Listbox.Items)
{
item.SelectedItem = true;
}
MessageBox.Show(" All tables Selected ");
}
The items in
SelectedTables.Itemsare notListBoxes. In your case, each item is astring. The easiest method for selecting all elements would be something like this: