# VB.NET Datagridview.. updating it PROBLEM



## denise_0006 (Jun 26, 2007)

Hi!
i want to make a search form like the one in google (advance search) where you have a lot of options..
i REALLY REALLY NEED HELP... for my project in class

I have a customer database having the fields:
CustomerID
CustomerFName
CustomerLName
CustomerBalance - current balance
... and so on...

Balance has three categories:
Positive - Customer Paid ahead
Zero
Negative - Customer has debt to the business

In my search form, i have three check boxes for the positive, zero and negative..
Also, there is a combobox for the FULL NAME of the customer.. i added items to it using comboxbox.item.add(value)
Ofcourse there is a search button and lastly the datagridview for the results...

I already know how to add rows in the datagridview...
using: datagridview1.item(column,row).value = "value"

My problem is during UPDATING The datagridview! the first click of the search button would be very easy. But the next clicks would be hard because i need to remove certain rows to satisfy the (another) search parameter.. my question is.. how do I update the datagridview during runtime???
NOTE: i did not bind the datagridview to any datasource.. i added each row manually... using again : datagridview1.item(column,row).value = "Value"
It would have been very easy if i used the built-in features in Visual Studio 2005 express edition. But then, i will never learn hard coding if I depend on these..PLUS the built-in features is way confusing for me.. i can't even customize it..


----------



## artur02 (Sep 24, 2007)

I'd recommend you to bind a datatable to datagridview. Basically datagridview is a visual component and I think you should manipulate data in a dataset. You will have to do the same things what you did in the datagridview: add rows, remove rows, etc.

So query the database into a dataset. If you want to filter the result, you can use a dataview component in ADO.NET just like in DBs. You can also manipulate the dataset (datatables) manually. When you finished modifying the dataset, call AcceptChanges on it and the datagridview will display the updated data.

So think about datagridview as a visual component and dataset as a datasource and data manipulation component.


----------



## pvc_ (Feb 18, 2008)

if you wanted to add the data manually, you should have used a listview, but now that you are using a datagrid, you have to set the control source and satisfy those options with the SQL statement you are writting. If you don't have the skills to do it in sql, then I'd just run the query and use string manipulation techniques to take out what I want, but your best bet would be using sql. Much faster, and a lot more efficient. Post what you want, and the sql you have and we may be able to help you come up with a decent statement that gets the job done.


----------



## denise_0006 (Jun 26, 2007)

hi! i just figured out how to solve my problem

to clear all rows so i could satisfy the new search, ... datagridview1.rows.clear()
to add because it was cleared, just datagridview1.rows.add()


----------

