Windows Develop Bookmark and Share   
 index > Windows Forms Data Controls and Databinding > BindingSource Filter and Changing Values
 

BindingSource Filter and Changing Values

Hello,

I have a filter set on my bindingsource i.e.

Me.BindingSource.Filter = "productPrice2 = 'WHATEVER'"

I then want to go through each row in my datagridview using this :

For Each row As DataGridViewRow In Me.DataGridView.Rows

row.Cells("WHATEVER").Value = "0"

Next

But because the filter is on this column I get an error saying 'Object reference not set to an instance of an object'. This obviously has to do with the fact the filter is on the column I am changing and therefore the bindingsource removes it as soon as I change it. Does anyone know a workaround for this. In the past I had to copy the 'cellA' value to 'cellB' and set the filter on 'cellB' then change the value of 'cellA', but I really dislike this approach.

Any suggestions would be REALLY appreciated

natetrost  Thursday, August 18, 2005 6:00 PM

I will typically go through in reverse order, iterating instead of using foreach. So, it would be something like this:


Dim row As DataGridViewRow

Dim i As Integer
For i = Me.DataGridView.Rows.Count - 1 To 0 Step -1
   row = Me.DataGridView.Rows(i)
   row.Cells("WHATEVER").Value = "0"
Next i

 

BonnieB  Sunday, August 21, 2005 10:16 PM

You can use google to search for other answers

Custom Search

More Threads

• Type BindToObject
• Problem Updating Dataset through Bindingsource
• BindingSource,DataSet,TableAdapter doesnt reflect changes
• DBConcurrencyException was unhandled
• Summary Rows in the DataGrid
• Syntax error in INSERT INTO statement (for .mdb file)
• muticolumn Datagridview Combo box
• Image Only Showing In First Two Rows
• BindingSource AddingNew
• Refresh Data in DataGridView