By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,480 Members | 763 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,480 IT Pros & Developers. It's quick & easy.

DatagridView Binding

P: n/a
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.
--
-John Northwest11
Please rate when your question is answered to help us and others know what
is helpful.
Apr 20 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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.
--------------------------
"John Bundy" <jm*****@gmail.com(remove)wrote in message
news:02**********************************@microsof t.com...
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.
--
-John Northwest11
Please rate when your question is answered to help us and others know
what
is helpful.

Apr 20 '07 #2

P: n/a
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.
--
-John Northwest11
Please rate when your question is answered to help us and others know what
is helpful.
"RobinS" wrote:
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.
--------------------------
"John Bundy" <jm*****@gmail.com(remove)wrote in message
news:02**********************************@microsof t.com...
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.
--
-John Northwest11
Please rate when your question is answered to help us and others know
what
is helpful.


Apr 20 '07 #3

P: n/a
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.
------------------------------------------
"John Bundy" <jm*****@gmail.com(remove)wrote in message
news:D7**********************************@microsof t.com...
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.
--
-John Northwest11
Please rate when your question is answered to help us and others know
what
is helpful.
"RobinS" wrote:
>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.
--------------------------
"John Bundy" <jm*****@gmail.com(remove)wrote in message
news:02**********************************@microso ft.com...
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.
--
-John Northwest11
Please rate when your question is answered to help us and others know
what
is helpful.



Apr 25 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.