Well to start out i am not sure if this is a problem in my code, or a possible problem with the DataView.RowFilter property, but here is what is occuring.
I have a DataGridView that's bound to a DataView. The user basically clicks on specific rows in the DataGridView and it sets a property in the DataGridViewRow to true... The IsSelected Property. Once the user is done they go ahead and click a button which removes all the rows they selected. First what occurs is the DataView is filtered using the dv.RowFilter = "IsSelected = True"; property. Then all the items are removed from the row.
Now that's ideal. Whats occuring is sometimes a row even though the property is set to true will not be included in the filter. I can not figure out for the life of me why. Does anyone know of any problems like this occuring to others
Here is a Code Sniplet to give you an idea, possibly its an error on my part:
dv_AssignedLocation.RowFilter =
"IsSelected = " + bool.TrueString;while(dv_AssignedLocation.Count > 0)
{
if (WebCore.Functions.isInt32Parseable(dv_AssignedLocation[0]["ID"].ToString()))
{
int ItemID = Int32.Parse(dv_AssignedLocation[0]["ID"].ToString());
LocationItem Location = SelectedRegion.Locations.ItemByID(ItemID);
if (Location != null)
{
if (!Location.Delete())
{
errors.AddRange(Location.ErrorList);
errormessage += "\n" + Location.City + ", " + Location.AbreviatedState + " " + Location.Zip;
isErrored = true;
}
else
{
// Transfer Row Information to Other DataGridView
dv_UnassignedLocation.Table.Rows.Add(dv_AssignedLocation[0].Row.ItemArray);
// Reset IsSelected Value to not Selected
dv_UnassignedLocation.Table.Rows[dv_UnassignedLocation.Table.Rows.Count - 1]["IsSelected"] = bool.FalseString;
// Delete UnAssigned Row
dv_AssignedLocation[0].Delete();
}
}
else
{
errormessage += "\n" + dv_AssignedLocation[0]["City"].ToString() + ", " +
dv_AssignedLocation[0]["AbreviatedState"].ToString() + " " +
dv_AssignedLocation[0]["Zip"].ToString();
isErrored = true;
}
}
else
{
errormessage += "\n" + "Location ID can not be Parsed - (" + dv_AssignedLocation[0]["ID"].ToString() + ") " + dv_AssignedLocation[0]["City"].ToString() + ", " + dv_AssignedLocation[0]["AbreviatedState"].ToString() + " " + dv_AssignedLocation[0]["Zip"].ToString();
isErrored = true;
}
IncrementAssignedProgressBar(1);
}

DataView.RowFilter Problem
amiller099
That doesn't matter if it is a bool variable im comparing to, a bool.TrueString, a "True" or "true" it all doesn't work.
I truely think something is wrong with the DataGridView.RowFilter method. I just a simple method that counts how many items are selected. Everytime i have only one item selected, once filtered it returns 0. It should return 1. Here is the code:
int countbefore = dv.Count; // This Value Gets Set to 1
bool valuebefore = dv[0]["IsSelected"]; // This Value Gets Set to True
dv.RowFilter = "IsSelected =" + bool.TrueString;
int SelectionCount = dv.Count; // This Value Gets Set to 0
dv.RowFilter = "";
return SelectionCount;
I believe once filtered it should still show 1. However after the filter is applied it sets it to 0. I have no idea why it does not pick up the one row that has its value set to true. Anyone have any ideas of whats going on Is there a bug in the RowFilter method
xiaoyifang
Not possible. The DataType of the Column is set to boolean. So if i try
IsSelected Like 'True'
It gives me a Runtime error.
The reason i set the DataType of the column to boolean was to reduce this problem from occuring, that way it could standardize the true and false. If you think that changing the datatype to string and modifying the filter to what you stated would work, i'll give it a shot, but i don't see how that would correct anything. Then again i don't see why i am gettingt this problem in the first place.
Gertus
Well in that case u might go for changing a different operator. you might try using LIKE operator instead of using "=". in that case you have to write the value in strings as show below.
"IsSelected LIKE 'true'"
Hope this helps.
-Jay
Sohailsoh
You know I thought the opposite. I actually originally had it set to
IsSelected = true.
But I started expierencing the problem so i wasn't sure if this could of been the problem so i switched it to the
IsSelected = bool.TrueString
Any other ideas possibly I am really going nuts here and it's not making any sense, at least not to me. Anyways Jay thanks for the help!
Matthew Petersen
BlackZombie
I have seen this weird problem for quite sometime now. I had used one fix and it worked in my case.
"IsSelected = true"
use above filter instead of "IsSelected = " + bool.TrueString.
Hope this helps.
-Jay
jreed
I decided to rather revive this old topic then create a new one...
It seems that after you apply a RowFilter to a DataView that has only one row, it will have count = 0, even when the value in that row matches conditions specified in the RowFilter. In the example above, if dv has only one row when filter is applied, dv.count will be zero after applying the filter, even if "IsSelected" column's value = true.
Please correct me if I'm wrong.
apedrosa
Well i just tried something like this
bool var = true;
RowFilter = "IsSelected=" + var;
It looks to be working good..