Refresh databinding?

G

Guest

I have a form where I want to populate a grid wih a dataset table.

To get the convenient designtime help I have dragged a typed dataset onto
the form, thus receiving a dataset control and a bindingsource control on the
fly.

As the dataset is quite heavy I want to reuse an existing dataset of the
main form, already loaded with data. The dataset is sent to the subform
constructor as a reference.

Problem is that when I change datasource of the grid I loose specific
formatting, set through the designer bindingsource.

My idea then was to try switching the datasource of the bindingsource
control. This seems to partly work. The bindingsource reports to have the
correct number of records. BUT they still don't show up in the grid!

Me.TblFeedbackBindingSource.DataSource = _ds

I expected some kind of refresh mechanism, but the data is not shown until I
add this line, where I specify the datasource of the grid ONCE AGAIN. Why is
this necessary to do again?
grdFeedback.DataSource = Me.TblFeedbackBindingSource
 
R

RobinS

What do you mean, when you change the data source of the grid? Is it
just
the one statement you've given?

One thing is if that is a dataset, you need to specify which table in
the
dataset the binding source should use, like this:

TblFeedbackBindingSource.DataSource = _ds.Tables("Customers")

If it's strongly typed, you can access the table name directly,
something
like this:

TblFeedbackBindingSource.DataSource = _ds.CustomerTable

HTH.
Robin S.
 
L

Linda Liu [MSFT]

Hi Jakob,

I performed a test based on your description but could not reproduce your
problem.

When the DataSource or DataMember property of a BindingSource component is
changed, and the BindingSource component has been set as the data source of
a DataGridView, data binding will update the data in the DataGridView
automatically and we needn't set the DataSource property of the
DataGridView control once again.

Note that if you change the DataSource property of the BindingSource
component, to get the data displayed correctly in the DataGridView control,
you should ensure that the new dataset instance has a DataTable with the
same name and schema as the previous dataset instance does.

Beside the above possibility, I think other possible reasons of your
problem may be that the DataSource property of your DataGridView control
has been changed somewhere else or the the BindingSource component whose
DataSource property you changed is not the one that the DataGridView
control is bound to.

If the problem is not still solved, you may send me your sample project
that could just reproduce the problem. To get my actual email address,
remove 'online' from my displayed email address.



Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
G

Guest

If the dataset has exactly the same schema but the refresh doesnt happen
automatically, call:

TblFeedbackBindingSource.ResetBindings(false)
 
G

Guest

My own fault!

Today I detected an event handler that had a line of code setting the grid
datasource to nothing, which of course explains all ..... !

Sorry about that.
 

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