I need help! I am developing a windows form application that will perform as a t
ID: 3917765 • Letter: I
Question
I need help! I am developing a windows form application that will perform as a tool for data analyzation. I have two checkedlistbox's , two datetimepicker's, a data grid view, and a series chart. My difficulty is using the checkedlistbox items as strings in if else if conditions. Ex : "If Eagle1 and Flash are checked use the data path connected to those boxes to populate the datagridview." The goal is to use the checked checkedlistbox items as a source of direction into which data paths will be used to populat my datagridview and chart.
i will include the necessary syntax:
the checked list boxes
public Main()
{
InitializeComponent();
checkedListBox2.Items.Add("Flash");
checkedListBox2.Items.Add("High Temp");
checkedListBox2.Items.Add("Low Temp");
checkedListBox2.Items.Add("Room Temp");
checkedListBox2.Items.Add("Low-High");
checkedListBox2.SelectedIndex = 0;
checkedListBox1.Items.Add("Eagle1");
checkedListBox1.Items.Add("Eagle2");
checkedListBox1.Items.Add("Eagle3");
checkedListBox1.Items.Add("Eagle4");
checkedListBox1.SelectedIndex = 0;
}
A SNIPPET OF ONE OF THE IF STATEMENTs in the submit button event
if (checkedListBox1.GetItemChecked(checkedListBox1.Items.IndexOf("Eagle1")))
{
if (checkedListBox2.GetItemChecked(checkedListBox2.Items.IndexOf("flash")))
{
fileDirectories.Add(\\Users\tnooluade\Desktop esult file path);
}
else if (checkedListBox2.GetItemChecked(checkedListBox2.Items.IndexOf("HighTemp")))
{
fileDirectories.Add(\\Users\tnooluade\Desktop esult file path);
}....................................................................
Explanation / Answer
You need to iterate on all checked items in checkedBoxList
Approach 2:
In your if clause directly check Index of the value in CheckedItems array
If(checkedListBox1.CheckedItems.IndexOf("Eagle" != -1)