Send a suggestion!

We're building a brand new version of the site, and we'd love to hear your ideas

Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Binding Navigator/Binding Source/DataGridView - how to?

Last post 09-02-2008 3:01 PM by egiroka. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 07-08-2008 9:03 AM

    • bfsog
    • Not Ranked
    • Joined on 09-25-2005
    • New Member
    • Points 40

    Binding Navigator/Binding Source/DataGridView - how to?

    I thought this would be pretty easy but I have been trying for 4 days now.

     What I am trying to do is

    • Query a database
    • Place the query results into a DataSet
    • Set the Binding Source to that DataSet
    • Set the Binding Navigator's DataSource to the Binding Source
    • Set the DataGridView's DataSource to the Binding Source

    However I cannot get the Binding Navigator to actually "navigate" through the returned data. The Navigator appears on my form, but the controls do not work and the row count says 1 whereas the DataGridView has around 300+ rows.

    I do not know what I am doing wrong, I appreciate any help.

    Here is the relevant code.

    </P><FONT size=2> <P>SqlCommand all = new SqlCommand("SELECT IndexNumber, VesselName, Active, Note, Agent, CustomerCode, ShippingAgent, CustomerPO, DeliverylabelReport, LastUpdate, EmailAddress from TableIndex", conn);
    SqlDataAdapter adpt = new SqlDataAdapter(all);
    DataSet ds = new DataSet();
    adpt.Fill(ds, "TableIndex");
    dgvCompanies.DataSource = ds.Tables[0];</P> <P>BindingNavigator _navigator;
    BindingSource _bindsrc = new BindingSource();</P> <P>_bindsrc.Add(ds);</P> <P>_navigator = new BindingNavigator(true);
    _navigator.Parent = this;
    _navigator.BindingSource = _bindsrc;
    _navigator.Dock = DockStyle.Top;</P> <P>dgvCompanies.DataSource = _bindsrc;</P> <P mce_keep="true">&nbsp;</P> <P>

    • Post Points: 10
  • Advertisement

    • Red Gate Software

    Advertisement

    Want to boost your .NET application performance?

    Some developers always seem to write efficient and lightening-fast code. What is their secret? It’s ANTS Profiler. “We improved the performance of the application up to 10 times” Dan Ports, Intrigma.

    Try it for yourself now.

  • 07-08-2008 3:59 PM In reply to

    Re: Binding Navigator/Binding Source/DataGridView - how to?

     

    Hi,

     

    This is because the data binding is not correct.  Use BindingSource to bind data with the DataGridView as well as BindingNavigator:

     

    Me.BindingSource1.DataSource = ds.Tables(0)

          Me.DataGridView1.DataSource = Me.BindingSource1

          Me.BindingNavigator1.BindingSource = Me.BindingSource1

     

    Hope this helps.

     

    Regards,

    Vinay

    ComponentOne LLC.

    www.componentone.com

     

     

    • Post Points: 15
  • 07-08-2008 8:31 PM In reply to

    • bfsog
    • Not Ranked
    • Joined on 09-25-2005
    • New Member
    • Points 40

    Re: Binding Navigator/Binding Source/DataGridView - how to?

    Thanks, I have searched high and low, it's working now.
    • Post Points: 5
  • 09-02-2008 3:01 PM In reply to

    • egiroka
    • Not Ranked
    • Joined on 09-02-2008
    • Hungary
    • New Member
    • Points 5

    Re: Binding Navigator/Binding Source/DataGridView - how to?

     

    Yeah, the same with me, but the cursor/pointer doesn't move on the datagrid when I page in the bindingnavigator.

    I'd like to have it moved to the actual record. How shall I extend the code above?

     

    Thx

    Egiroka 

    • Post Points: 5
Page 1 of 1 (4 items)