Home All Groups Group Topic Archive Search About

DataBinding with Unbound Columns and calling EndCurrentEdit

Author
20 Jun 2006 6:59 PM
Aspnot
I have a form that is setup in a Master/Detail configuration.  The Detail
section is represented with a DataGridView.  Some of the columns in this
DataGridView control are unbound.

When a user clicks the Cancel button, I loop through the tables in my
DataSet and call EndCurrentEdit() to determine if HasChanges() is True.  And
then prompt the user and allow them to Cancel out of the exit.  If the user
chooses Cancel and any changes have been made to the Master table in the
DataSet, my unbound columns lose their data due to the fact that I called
EndCurrentEdit() on the Master table.

These Unbound columns come from my database, so I would rather not have to
reload them in this scenario.

Do I have to reload them?  Is there a way to halt them from getting
refreshed?  If not, what is the best event to react to to reload the
information?

PS - I realize that I can add these fields to my DataSet, but I would rather
not have to do that.  This application is currently set to run locally, but
this company has a remote office that we may link in through web services and
I would hate to have that extra overhead for every save.

Author
21 Jun 2006 5:37 AM
Cor Ligthert [MVP]
ASPNOT,

Are you sure of that, did you save your table in a Session (or somewhere
else) and have set it back using the load of your form in the isPostBack
situation?

Cor

Show quoteHide quote
"Aspnot" <NOSPAM_Aspnot_NOSPAM@nc.rr.com> schreef in bericht
news:1A282540-28B6-47F8-9F7F-C6A563F6D260@microsoft.com...
>I have a form that is setup in a Master/Detail configuration.  The Detail
> section is represented with a DataGridView.  Some of the columns in this
> DataGridView control are unbound.
>
> When a user clicks the Cancel button, I loop through the tables in my
> DataSet and call EndCurrentEdit() to determine if HasChanges() is True.
> And
> then prompt the user and allow them to Cancel out of the exit.  If the
> user
> chooses Cancel and any changes have been made to the Master table in the
> DataSet, my unbound columns lose their data due to the fact that I called
> EndCurrentEdit() on the Master table.
>
> These Unbound columns come from my database, so I would rather not have to
> reload them in this scenario.
>
> Do I have to reload them?  Is there a way to halt them from getting
> refreshed?  If not, what is the best event to react to to reload the
> information?
>
> PS - I realize that I can add these fields to my DataSet, but I would
> rather
> not have to do that.  This application is currently set to run locally,
> but
> this company has a remote office that we may link in through web services
> and
> I would hate to have that extra overhead for every save.
Author
21 Jun 2006 1:24 PM
Aspnot
Thanks for the reply, Cor.

This is a VB form, not an ASP.NET form.  Sorry for not specifying that.

I have put a bandaid on this by simply reloading the unbound fields after
the call to EndCurrentEdit().  I don't like making all of these extra calls
to the database, but I had to get something in place so I could keep moving
forward with this application I am working on.

Any thoughts on another way to deal with this?

PS - In some of my reading yesterday, I found a statement that fit why this
is happening.  I thought I knew why, but wanted to see it written somewhere. 
If the DataTable has any changes, the data in the DataSet is refreshed, which
causes the bound controls to also be refreshed.  Also, any related tables are
also refreshed which explains why my DataGridView data is being refreshed.

Show quoteHide quote
"Cor Ligthert [MVP]" wrote:

> ASPNOT,
>
> Are you sure of that, did you save your table in a Session (or somewhere
> else) and have set it back using the load of your form in the isPostBack
> situation?
>
> Cor
>
> "Aspnot" <NOSPAM_Aspnot_NOSPAM@nc.rr.com> schreef in bericht
> news:1A282540-28B6-47F8-9F7F-C6A563F6D260@microsoft.com...
> >I have a form that is setup in a Master/Detail configuration.  The Detail
> > section is represented with a DataGridView.  Some of the columns in this
> > DataGridView control are unbound.
> >
> > When a user clicks the Cancel button, I loop through the tables in my
> > DataSet and call EndCurrentEdit() to determine if HasChanges() is True.
> > And
> > then prompt the user and allow them to Cancel out of the exit.  If the
> > user
> > chooses Cancel and any changes have been made to the Master table in the
> > DataSet, my unbound columns lose their data due to the fact that I called
> > EndCurrentEdit() on the Master table.
> >
> > These Unbound columns come from my database, so I would rather not have to
> > reload them in this scenario.
> >
> > Do I have to reload them?  Is there a way to halt them from getting
> > refreshed?  If not, what is the best event to react to to reload the
> > information?
> >
> > PS - I realize that I can add these fields to my DataSet, but I would
> > rather
> > not have to do that.  This application is currently set to run locally,
> > but
> > this company has a remote office that we may link in through web services
> > and
> > I would hate to have that extra overhead for every save.
>
>
>
Author
22 Jun 2006 11:10 AM
Cor Ligthert [MVP]
ASPNOT,

I tried it like this, but everything is as I expect.

\\\
Public Class Form1
    Private dt As New DataTable
    Private Sub Form1_Load(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles MyBase.Load
        Dim strConn As String = _
        "Server = .\SQLEXPRESS;Database = NorthWind; Integrated Security =
SSPI;"
        Dim conn As New SqlClient.SqlConnection(strConn)
        Dim da As New SqlClient.SqlDataAdapter("Select * from orders", conn)
        da.Fill(dt)
        dt.Columns(2).ColumnMapping = MappingType.Hidden
        dt.Rows(0)(2) = 12
        DataGridView1.DataSource = dt
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click
        DirectCast(BindingContext(dt), CurrencyManager).EndCurrentEdit()
        dt.Columns(2).ColumnMapping = MappingType.Element
        DataGridView1.DataSource = Nothing
        DataGridView1.DataSource = dt
        DataGridView1.Refresh()
    End Sub
End Class
///

I hope this helps,
Cor

Show quoteHide quote
"Aspnot" <NOSPAM_Aspnot_NOSPAM@nc.rr.com> schreef in bericht
news:11B08403-6CDF-4E00-9FBB-22C77C3F52CA@microsoft.com...
> Thanks for the reply, Cor.
>
> This is a VB form, not an ASP.NET form.  Sorry for not specifying that.
>
> I have put a bandaid on this by simply reloading the unbound fields after
> the call to EndCurrentEdit().  I don't like making all of these extra
> calls
> to the database, but I had to get something in place so I could keep
> moving
> forward with this application I am working on.
>
> Any thoughts on another way to deal with this?
>
> PS - In some of my reading yesterday, I found a statement that fit why
> this
> is happening.  I thought I knew why, but wanted to see it written
> somewhere.
> If the DataTable has any changes, the data in the DataSet is refreshed,
> which
> causes the bound controls to also be refreshed.  Also, any related tables
> are
> also refreshed which explains why my DataGridView data is being refreshed.
>
> "Cor Ligthert [MVP]" wrote:
>
>> ASPNOT,
>>
>> Are you sure of that, did you save your table in a Session (or somewhere
>> else) and have set it back using the load of your form in the isPostBack
>> situation?
>>
>> Cor
>>
>> "Aspnot" <NOSPAM_Aspnot_NOSPAM@nc.rr.com> schreef in bericht
>> news:1A282540-28B6-47F8-9F7F-C6A563F6D260@microsoft.com...
>> >I have a form that is setup in a Master/Detail configuration.  The
>> >Detail
>> > section is represented with a DataGridView.  Some of the columns in
>> > this
>> > DataGridView control are unbound.
>> >
>> > When a user clicks the Cancel button, I loop through the tables in my
>> > DataSet and call EndCurrentEdit() to determine if HasChanges() is True.
>> > And
>> > then prompt the user and allow them to Cancel out of the exit.  If the
>> > user
>> > chooses Cancel and any changes have been made to the Master table in
>> > the
>> > DataSet, my unbound columns lose their data due to the fact that I
>> > called
>> > EndCurrentEdit() on the Master table.
>> >
>> > These Unbound columns come from my database, so I would rather not have
>> > to
>> > reload them in this scenario.
>> >
>> > Do I have to reload them?  Is there a way to halt them from getting
>> > refreshed?  If not, what is the best event to react to to reload the
>> > information?
>> >
>> > PS - I realize that I can add these fields to my DataSet, but I would
>> > rather
>> > not have to do that.  This application is currently set to run locally,
>> > but
>> > this company has a remote office that we may link in through web
>> > services
>> > and
>> > I would hate to have that extra overhead for every save.
>>
>>
>>