Link to home
Start Free TrialLog in
Avatar of FCapo
FCapo

asked on

Vb.net datagridview

Hi,

I have a datagridview that's binding to a dataset,

I filtered the bindingsource using a specific string, when I change values in the datagrid the row gets filtered out of the datagridview, because of the current filter, Is there a way to prevent the datagridview from filtering out the rows out when I change the values? I know it's only doing what I asked of it, I just don't want the rows to dissapear when I change the values in them.
Avatar of Ark
Ark
Flag of Russian Federation image

You can create filtered dataview and use it as a datasource for bindingsource
Dim dt As New DataTable
'... fill datatable
Dim view As New DataView(dt)
view.RowFilter = "myColumn>5" 'your filter here
Dim bs As New BindingSource
bs.DataSource = view
grid.DataSource = bs

Open in new window

Avatar of FCapo
FCapo

ASKER

Hi,

I'm not sure how to do the dataview that way,

This is how I bind my datagridview

        clientAccessData = New ClientsAccess
        cliAccDataSet = clientAccessData.getrelateddata
        cliAccessBindingsource = New BindingSource

        With cliAccessBindingsource
            .DataSource = cliAccDataSet
            .DataMember = "projets"
        End With

  DataGridView1.DataSource = cliAccessBindingsource

cliAccessBindingsource.Filter = "prjNumber like '%bs%' AND prjStage<>'Completed' and prjStage<>'Inactif'"

Open in new window

Dim view = New DataView(cliAccDataSet.Tables("projets"))
view.RowFilter = "prjNumber like '%bs%' AND prjStage<>'Completed' and prjStage<>'Inactif'"

cliAccessBindingsource.DataSource = view

DataGridView1.DataSource = cliAccessBindingsource

Open in new window

Avatar of FCapo

ASKER

The result is the same though,

If I change values in the datagrid the row still gets filtered out off the screen,

what is the advantage of creating a view.

My problem was this:

Filter all rows that contain the employee John
The datagridview shows 5 rows that contain John
I then change the employee name in those rows to Fred
As I change the name to Fred the rows dissapear off the grid (because it is filtering only those that contain John)

When I try to save it, the changes I made don't register, some times it saves 3 out of the 5 changes I made, some times 1, sometimes it gives me an error.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.