This code pre-filters a dataGridView so only the checked items in the list will be displayed.
The problem I'm facing is that the code somehow omits the very last item every time, unless I uncheck, check again and press "Go".
This is my code:
public partial class Notifications : Form
{
string filterstring = "";
int count = 0;
private void checkedListBox_ItemCheck(object sender, System.EventArgs e)
{
// Loop through all items in the checkedBoxes.
foreach (object itemChecked in checkedListBox.CheckedItems)
{
if (count != 0)
{
filterstring += "OR Responsible = '" + itemChecked.ToString() + "'";
}
else
filterstring += "Responsible = '" + itemChecked.ToString() + "'";
count += 1;
}
}
private void button1_Click(object sender, EventArgs e)
{
DataTableCollection tables = myDatabaseDataSet.Tables;
DataView view = new DataView(tables[0]);
BindingSource source = new BindingSource();
source.DataSource = view;
dataGridView1.DataSource = source;
source.Filter = filterstring;
}
I know the solution might be silly but I can't figure it out.