S
sherifffruitfly
Hi,
I've got a checked list box, and a "go' button on the form. Each item
in the checked list box is associated with a program (say notepad,
calc, etc.). When the user clicks "go", every item that is checked is
to be run.
I'm looking for an elegant and extensible way to do this. I'm currently
using an if block, which just seems silly to me. Structurally, it's the
equivalent of the below. Any ideas on alternatives would be much
appreciated. What I have looks asinine.
In particular, it would be nice to be able to "run all checked",
without having to specify at compile time just what the possibilities
are (ie, the user might be able to add items to the list).
thanks,
cdj
==========================
private void btn_Gather_Click(object sender, System.EventArgs e)
{
if (chkListBox_AvailProgs.CheckedItems.Count == 0)
{
MessageBox.Show("There are no programs checked.", "Program selector
Error");
}
else if (dateTimePickerStart.Value.DayOfWeek.ToString() == "Sunday"
|| dateTimePickerStart.Value.DayOfWeek.ToString() == "Saturday")
{
MessageBox.Show("Date must be Monday-Friday.", "Program selector
Error");
}
else
{
if (chkListBox_AvailProgs.CheckedItems.Contains("Notepad"))
{
RunNotepad();
}
if (chkListBox_AvailProgs.CheckedItems.Contains("Calc"))
{
RunCalc();
}
if (chkListBox_AvailProgs.CheckedItems.Contains("Paint"))
{
RunPaint();
}
}
}
I've got a checked list box, and a "go' button on the form. Each item
in the checked list box is associated with a program (say notepad,
calc, etc.). When the user clicks "go", every item that is checked is
to be run.
I'm looking for an elegant and extensible way to do this. I'm currently
using an if block, which just seems silly to me. Structurally, it's the
equivalent of the below. Any ideas on alternatives would be much
appreciated. What I have looks asinine.
In particular, it would be nice to be able to "run all checked",
without having to specify at compile time just what the possibilities
are (ie, the user might be able to add items to the list).
thanks,
cdj
==========================
private void btn_Gather_Click(object sender, System.EventArgs e)
{
if (chkListBox_AvailProgs.CheckedItems.Count == 0)
{
MessageBox.Show("There are no programs checked.", "Program selector
Error");
}
else if (dateTimePickerStart.Value.DayOfWeek.ToString() == "Sunday"
|| dateTimePickerStart.Value.DayOfWeek.ToString() == "Saturday")
{
MessageBox.Show("Date must be Monday-Friday.", "Program selector
Error");
}
else
{
if (chkListBox_AvailProgs.CheckedItems.Contains("Notepad"))
{
RunNotepad();
}
if (chkListBox_AvailProgs.CheckedItems.Contains("Calc"))
{
RunCalc();
}
if (chkListBox_AvailProgs.CheckedItems.Contains("Paint"))
{
RunPaint();
}
}
}