I'm using Select on a datatable and am getting unexplainable results. Using Visual Studio 2013 and VB.NET.
I have a dataset which is the datasource of a datagridview. The dataset has a column which contains boolean values, which are represented as a checkbox by the datagridview. I'm using the solution from jsturtevand in this thread to make sure the dgv is updated after the user moves the mouse away from the checkbox. Each time the user changes the checkbox value, a corresponding row is updated in the database.
In my form the user can click on apply and a bunch of actions will be executed depending on which checkboxes are checked. The code I use to find the selected items is:
Dim rows() As DataRow
rows = dsFiles.Tables(0).Select("isActive = True")
When the user selects the checkboxes, does another action that changes focus and then presses apply, I get the correct results. If the user changes a checkbox and presses apply immediately the select statement won't find the last change. So if he has two items selected, selects a third and immediately presses apply, the select statement only finds two items. Here is the weird part: If I check the dataset before executing select, it contains the correct data and if I use a loop like this
For Each row As DataRow In dsFiles.Tables(0).Rows
If row("isActive") = True Then count += 1
Next
then I get the correct number of items. Which means .Select returns different data then when I do the same thing it is supposed to do by hand. And how is any of this related to the user pressing apply before leaving focus when the dgv, the database and the dataset are all updated correctly? Everything works fine, and yet .Select just doesn't work. Of course I could just as well use a loop, but I want to know how this is even possible.
Edit: Wrongly assumed .Select was a Linq method. Removed references to Linq.