DatagridView Binding

G

Guest

New to databinding in vs2005, I always did it manually in 2003. I have no
problem loading comboboxes, and a change in that combobox changes the data in
the textboxes but I can not figure out a way to get the data in a
datagridview to change. For example 2 columns are ID and amount_paid, the
datagridview loads on form load with all ID's and amounts. How do I get it to
only bring back the selected ID. Sounds like I may need to change the SQL on
the fly but there has to be a way to do it through the binding. Thanks for
any help.
 
R

RobinS

If you bind your datagridview to a BindingSource, then when they change the
ComboBox, you can add a filter to the bindingsource, and it will filter
your datagridview.

Robin S.
 
G

Guest

Well i'm trying that, I have 2 tables, the ID appears on both the Student
table and the Payment table. The combobox is bound to the student table,
displaying name and value is ID. Datagridview datasource is set to the
payment table displaying payment number and amount paid. Then I go to the
properties/databindings and have set that to Student table/ID.
 
R

RobinS

I don't understand. You are binding your datagridview to the same table you
are using for the binding on the combobox?

You need to bind the combobox to the student table, and the datagridview to
the payment table. It would be good to have a separate binding source for
each of those.

Then handle the selectedindexchanged event on the combobox, and when they
change the selected index, filter the datagridview on the matching column
using the binding source.

You will need to do something like keep a private variable in your class to
tell when you are loading, because the selectedindexchanged event will be
fired repeatedly when it's being populated, and you don't want to filter
your dgv when it's loading. So set the private variable (like _Loading) to
true as a default, and in your form_load (at the end), set it back to
false. In you selectedindexchanged, check that variable, and only filter
the dgv if it is false.

Robin S.
------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top