Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > .NET 2.0 and Visual Studio. 2005 > .NET Framework 2.0
|
.NET Framework 2.0 For discussion of the Microsoft .NET Framework 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the .NET Framework 2.0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 31st, 2006, 05:40 AM
Registered User
 
Join Date: Aug 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default bindingSource position after table.AddRow()

Hi all, here is my problem:

(system is VS 2005, C#, ADO .NET 2)
I have a bindingsource, a datagrid, and set of details like fields on the same
form. Next, there are following bindings set:

    void Init()
    {
        BindingSource.DataSource = someLocalTable
        datagrid.DataSource = BindingSource

        for every control
        {
            Control.DataBinding.Add("...", BindingSource, "...")
        }
    }

Moving through a datagrid changes the data in bound detail controls, hence
BindingSource too, changes position. Changing data in controls changes
the data in selected dataGrid row.

The problem is:
I have a button "Insert New", that does exactly this:

1. adds a new row in the local someLocalTable and
   fills it with the default values:
       DataRow dr = someLocalTable.NewRow();
    ... fill default values
        someLocalTable.Rows.Add(dr);

2. TRIES TO CHANGE THE BINDINGSOURCE-s POSITION TO LAST(newly created table row)
3. This is the step where after changing position on the bindingSource
   to the newly created row (.MoveLast()), you expect detail fields change
   to null (or empty), and dataGrid changes the ActiveRow and position

However, after adding new row to someLocalTable, I can not change the position
of the bindingSource to that new row. BindingSource.Count returns good nr. of
rows, including the newly created. I tried a lots of things, like rebind all
controls like on the Init method, still no luck. Am I missing something here?
I forgot to mention that the grid is actually Infragistics ultraGrid, but that
doesn't change the basic concept...

Mike


 
Old September 12th, 2006, 02:15 PM
Registered User
 
Join Date: Sep 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Did you try using the Add / AddNew methods of the BindingSource to create your new row? Since the BindingSource handles Currency Management, adding via the BindingSource instead of the dataTable should set the current position to the newly added row. This should take care of most of what you want to do (add a new row, set current position on new row regardless of sorting, all bound fields will show blank contents of new row), and all that would be left is to fill in the defaults.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Position barski XSLT 5 July 11th, 2007 01:54 PM
BindingSource.Filter bufanator Visual Basic 2005 Basics 2 May 23rd, 2007 10:16 AM
bindingsource validating gpizzuto Visual Basic 2005 Basics 0 April 26th, 2006 05:27 PM
Column position in table kasanar SQL Server 2000 7 June 2nd, 2005 02:00 AM
Position of a table gisvb Dreamweaver (all versions) 1 January 5th, 2004 05:46 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.