Connecting a BindingNavigator to a DataGridView bound to XML


M

michael sorens

I have generated an XmlDocument, then bound it to a DataGridView (thanks
to a pointer from PeterBromberg in a separate, recent posting). Now I want
to connect a BindingNavigator, but my rudimentary attempt failed.

In the Visual Designer I added a BindingSource bs, then a BindingNavigator
bn, and assigned bs to the BindingSource property of bn. In code, I
generate my XmlDocument, massage it to fit into a DataSet, then assign it
to the DataSource property of my DataGridView dgv. That all works.

I then tried setting bs.DataSource to dgv.DataSource and bs.DataMember to
dgv.DataMember. The only thing that did for me is provide a correct record
count in the Binding Navigator when executed. The only affect of the
navigation arrows is to alter the count in the BindingNavigator--no
changes in the active row in the DataGridView occur. So clearly I am
missing one or more pieces...
 
Ad

Advertisements

L

Linda Liu [MSFT]

Hi Michael,

To alter the current row in the DataGridView when clicking the navigation
arrows of the BindingNavigator, you should set the DataSource property of
the DataGridView to the BindingSource instance bs, rather than the dataset
instance.

Every data source has a BindingManagerBase object associated with it. If a
data source is a list, we could change the Position property of
BindingManagerBase object to change the current item in the data source.

The BindingManagerBase objects associated with the BindingSource bs and the
dataset instance are not the same one. We could access the
BindingManagerBase objects using the following code.

BindingManagerBase bm1= bs.CurrencyManager;
BindingManagerBase bm2 =this.BindingContext[bs]; // bm1 == bm2
BindingManagerBase bm = this.BindingContext[this.dataSet11, "TableName"];
// bm1 <> bm

When you set the BindingSource property of the BindingNavigator to bs and
click the navigation arrows of the BindingNavigator, BindingNavigator
manipulates the BindingManagerBase object associated with the
BindingSource. In this case, you should set the DataSource property of the
DataGridView to the BindingSource bs.

If you have anything unclear, please feel free to let me know.


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.
 
M

Marc Gravell

I think you need to assign
bs.DataSource = (your new DataSet);
dgv.DataSource = bs;
i.e. tell dgv to use (for its data) the BindingSource data-source that
is bound to the navigator; otherwise they are independept.

Any use?

Marc
 
Ad

Advertisements

M

michael sorens

Thanks to both Linda (for supplying both the answer and the background)
and to Marc (for supplying the answer in a very concise format:). I found
both useful.
 

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