Click here to Skip to main content
15,918,330 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
I have an application which uses a datagridview that is bound to a filtered bindingsource. The problem is that I am not allowed to add a new row in the datagridview, yet when I remove the filter from the binding source I can add rows to the datagridview.

Is there a way to fix this problem?
Posted
Comments
Herman<T>.Instance 17-Aug-11 16:31pm    
what is your filter statement?

1 solution

If the problem is in the UI, have you set AllowUserToAddRows [^] to false?

If the problem is that you cannot programmatically add rows to the datagridview, shouldn't you add the data into the source of the binding instead of the datagridview?
 
Share this answer
 
v2
Comments
Member 8024969 17-Aug-11 17:24pm    
Shouldn't I be able to add rows to the datagrid then update the database table after all the changes have been made?

The AllowUserToAddRows is set to True.
and it does work as I have said before when I remove the line

Me.DetailsBindingSource.Filter = "Account LIKE '%" & Me.cboAccName.Text & "%'"

I am allowed to change rows and save them but not add new rows through the datagrid when that filer is active.
Wendelius 17-Aug-11 17:38pm    
Ok, I misunderstood your question a bit, sorry for that.

So when you have a filter you cannot add new rows using the UI, correct? If that's the case, have you checked what is the value of AllowNew and AllowEdit of the bindingSource before and after you add the filter?

Also have you tried calling the bindingsource's AddNew directly from your code after you set the filter, does it throw an exception?
Member 8024969 17-Aug-11 20:20pm    
That is correct. I can only addnew row using the datagrid UI before applying the filter.
The thing is I have to use the datagrid to make changes to the database.
AllowNew and AllowEdit both set to True before and after the filter.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900