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

Detecting value change in a datagrid cell

P: n/a
Greetings,

I am trying to find out how to do something that on the surface seems like
it should be very simple to do.

I have a datagrid with a datatable bound to it using the SetDataBinding
method. What I am trying to accomplish is to detect if a value has changed
in any cell so that if a user closes the form without saving first, I want to
prompt to save changes. I don't want to prompt if there were no changes.

I tried doing it at the datatable level, but apparently changes to the
datagrid do not automatically get replicated to the underlying datasource
because that didn't work.

Is there some way to do this? I am using VS.NET 2003 and C#.

Thanks in advance for any help!

Mike
Jan 31 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
mike,

You need the endcurrentedit to push the latest cell change into the
datasource that you use.

If you want to do it more in the datagrid itself, than you can use a
textbox.event. Here is just the validate but you can use of course as well
the value change ones.

http://www.vb-tips.com/dbpages.aspx?...d-203ca99d2825

Cor

"Mike" <Mi**@discussions.microsoft.comschreef in bericht
news:AD**********************************@microsof t.com...
Greetings,

I am trying to find out how to do something that on the surface seems like
it should be very simple to do.

I have a datagrid with a datatable bound to it using the SetDataBinding
method. What I am trying to accomplish is to detect if a value has
changed
in any cell so that if a user closes the form without saving first, I want
to
prompt to save changes. I don't want to prompt if there were no changes.

I tried doing it at the datatable level, but apparently changes to the
datagrid do not automatically get replicated to the underlying datasource
because that didn't work.

Is there some way to do this? I am using VS.NET 2003 and C#.

Thanks in advance for any help!

Mike

Jan 31 '07 #2

P: n/a
Hi Cor,

Thanks for taking the time. Actually, the fact that a change in the
datagrid doesn't automatically replicate to the datasource is a good thing in
my case since if they didn't want to save a change I wouldn't have to do
anything.

I did find a solution to what I was looking for by using the
CurrentCellChanged event. I found it from another post and edited it to work
for me:

private void dgPlayers_CurrentCellChanged(object sender, System.EventArgs e)
{
if(origValue==null)
{
origDataCell=this.dgPlayers.CurrentCell;
origValue=this.dgPlayers[this.dgPlayers.CurrentCell];
}
else
{
if(!origValue.Equals(this.dgPlayers[origDataCell]))
{
hasChanges = true;
}
origDataCell=this.dgPlayers.CurrentCell;
origValue=this.dgPlayers[this.dgPlayers.CurrentCell];
}

}

In the Closing event of the form I check the hasChanges variable for a true
state.

It works like a champ!

Thanks,

Mike
"Cor Ligthert [MVP]" wrote:
mike,

You need the endcurrentedit to push the latest cell change into the
datasource that you use.

If you want to do it more in the datagrid itself, than you can use a
textbox.event. Here is just the validate but you can use of course as well
the value change ones.

http://www.vb-tips.com/dbpages.aspx?...d-203ca99d2825

Cor

"Mike" <Mi**@discussions.microsoft.comschreef in bericht
news:AD**********************************@microsof t.com...
Greetings,

I am trying to find out how to do something that on the surface seems like
it should be very simple to do.

I have a datagrid with a datatable bound to it using the SetDataBinding
method. What I am trying to accomplish is to detect if a value has
changed
in any cell so that if a user closes the form without saving first, I want
to
prompt to save changes. I don't want to prompt if there were no changes.

I tried doing it at the datatable level, but apparently changes to the
datagrid do not automatically get replicated to the underlying datasource
because that didn't work.

Is there some way to do this? I am using VS.NET 2003 and C#.

Thanks in advance for any help!

Mike


Feb 1 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.