对列表框中选择的每个项目调用一个方法。我需要以编程方式调用列表框中每个项目的方法,而无需选择每个项目。这是方法:
private void btnMove_Click(object sender, EventArgs e)
{
Cursor.Current = Cursors.WaitCursor;
CreateFoldersMoveFiles(); // work is performed in this method with the selected listbox text.
if (listBox2.SelectedIndex < listBox2.Items.Count - 1)
{
listBox2.SelectedIndex = listBox2.SelectedIndex + 1;
}
Cursor.Current = Cursors.Default;
}
由于它不是您问题的一部分,我相信您在 CreateFoldersMoveFiles 方法中使用 listBox2.SelectedItem 来获取所选项目,然后对其进行处理。相反,您需要允许 CreateFoldersMoveFiles 接受争论,并在您的 BtnMove_Click 中循环遍历列表框项并调用该方法。
foreach (var item in listBox1.Items)
{
CreateFoldersMoveFiles(item);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句