如何比较列表框项与数组项
How to Compare Listbox item(s) with Array Items
我有一个复选框,其中包含一些 exe/application 个名称。当我要去 select 其中任何一个时,它应该开始。
现在应用程序正在启动,但是如果我从路径中不存在的复选框中 selected exe/application 名称(我在下面写过),即如何对其进行验证。我的代码是:
if (chkListBox.CheckedItems.Count > 0)
{
for (int i = 0; i < chkListBox.CheckedItems.Count; i++)
{
string path = @"D:\Development\Latest\ConsoleApplication1\ConsoleApplication1\bin\Debug";
string files = Directory.GetDirectoryRoot(path);
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = Path.Combine(path, chkListBox.Items[i].ToString() + ".exe")
}
};
process.StartInfo.UseShellExecute = false;// Beacuse I am using Process class
process.StartInfo.CreateNoWindow = true;
process.Start();
}
}
else
{
MessageBox.Show("Item Not selected");
}
string path = @"D:\Development\Latest\ConsoleApplication1\ConsoleApplication1\bin\Debug";
string files = Directory.GetDirectoryRoot(path);
var exeNotFoundList = new List<string>();
for (int i = 0; i < chkListBox.CheckedItems.Count; i++)
{
var exeFilePathWithName = Path.Combine(path, chkListBox.Items[i].ToString() + ".exe");
if(!File.Exists(exeFilePathWithName))
{
exeNotFoundList.Add(exeFilePathWithName);
continue;
}
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = exeFilePathWithName
}
};
process.StartInfo.UseShellExecute = false;// Beacuse I am using Process class
process.StartInfo.CreateNoWindow = true;
process.Start();
}
if(exeNotFoundList.Count > 0)
{
var errorMessage = String.Join(String.Empty, exeNotFoundList.ToArray());
MessageBox.Show(errorMessage);
}
我有一个复选框,其中包含一些 exe/application 个名称。当我要去 select 其中任何一个时,它应该开始。 现在应用程序正在启动,但是如果我从路径中不存在的复选框中 selected exe/application 名称(我在下面写过),即如何对其进行验证。我的代码是:
if (chkListBox.CheckedItems.Count > 0)
{
for (int i = 0; i < chkListBox.CheckedItems.Count; i++)
{
string path = @"D:\Development\Latest\ConsoleApplication1\ConsoleApplication1\bin\Debug";
string files = Directory.GetDirectoryRoot(path);
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = Path.Combine(path, chkListBox.Items[i].ToString() + ".exe")
}
};
process.StartInfo.UseShellExecute = false;// Beacuse I am using Process class
process.StartInfo.CreateNoWindow = true;
process.Start();
}
}
else
{
MessageBox.Show("Item Not selected");
}
string path = @"D:\Development\Latest\ConsoleApplication1\ConsoleApplication1\bin\Debug";
string files = Directory.GetDirectoryRoot(path);
var exeNotFoundList = new List<string>();
for (int i = 0; i < chkListBox.CheckedItems.Count; i++)
{
var exeFilePathWithName = Path.Combine(path, chkListBox.Items[i].ToString() + ".exe");
if(!File.Exists(exeFilePathWithName))
{
exeNotFoundList.Add(exeFilePathWithName);
continue;
}
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = exeFilePathWithName
}
};
process.StartInfo.UseShellExecute = false;// Beacuse I am using Process class
process.StartInfo.CreateNoWindow = true;
process.Start();
}
if(exeNotFoundList.Count > 0)
{
var errorMessage = String.Join(String.Empty, exeNotFoundList.ToArray());
MessageBox.Show(errorMessage);
}