By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,224 Members | 1,120 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,224 IT Pros & Developers. It's quick & easy.

DataBinding with Unbound Columns and calling EndCurrentEdit

P: n/a
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.
Jun 20 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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" <NO******************@nc.rr.com> schreef in bericht
news:1A**********************************@microsof t.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.

Jun 21 '06 #2

P: n/a
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" <NO******************@nc.rr.com> schreef in bericht
news:1A**********************************@microsof t.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.


Jun 21 '06 #3

P: n/a
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

"Aspnot" <NO******************@nc.rr.com> schreef in bericht
news:11**********************************@microsof t.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" <NO******************@nc.rr.com> schreef in bericht
news:1A**********************************@microsof t.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.


Jun 22 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.