I've seen a couple similar questions but I can't figure out what I'm doing wrong. I have a list box where I want all selected test files to be listed without the whole path. With this current code, no text is being entered into the list box. Where am I going wrong?
if (cmdBrowse.ShowDialog() == DialogResult.OK)
{
string testNameShort = Path.GetFileName(listboxTestsToRun.Text.ToString());
listboxTestsToRun.Items.Add(testNameShort);
}
Thanks in advance!
Supposing that cmdBrowse is an OpenFileDialog and you want the filename selected by your user to be added to the listbox. In this case you code this
if (cmdBrowse.ShowDialog() == DialogResult.OK)
{
if(cmdBrowse.FileName.Length > 0)
{
string testNameShort = Path.GetFileName(cmdBrowse.FileName);
listboxTestsToRun.Items.Add(testNameShort);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With