473,382 Members | 1,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Detecting value change in a datagrid cell

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
2 2915
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Alex | last post by:
Hi all... I have a DataGrid bound to a DataTable. My DataTable gets updated programmatically as it contains the status of a number of worker threads. Each "main" worker thread launches a...
3
by: Randy | last post by:
Hello, How would one go about detecting which row/column was clicked in a datagrid. I'm sure it can be done but I can't figure it out. Thanks
2
by: kscdavefl | last post by:
I have a column on a web page datagrid that contains a value. I want to take the value and populate another cell on the grid. If the value in cell number 6 is 0 I want to make the value in cell 1...
3
by: Simon Prince | last post by:
Hi, I'm trying detect an empty cell in a datagrid when the content is posted back to the server. My code is... Dim vDgi_GridItem As DataGridItem For Each vDgi_GridItem In...
3
by: Richard | last post by:
I'm trying to change a value of a cell based on another before the grid is displayed. I'm using the ItemDataBound event like this for a simple test: Select Case e.Item.ItemType Case...
2
by: David Batt | last post by:
Hi, I need to determine when data in a datagrid bound to a dataset has changed and thus make updates accordingly. I would of thought the code below would detect when a change has been made to...
3
by: John Smith | last post by:
I'm looking into this peace of code: protected void DropDown_SelectedIndexChanged(object sender, EventArgs e) { DropDownList list = (DropDownList)sender; TableCell cell = list.Parent as...
2
by: John Smith | last post by:
Will this line of the code: item.Cells.Text = "Some text..."; change only DataGrid visual value or it will also change value in the DataSource? How can I change value in DataSource? ...
2
by: harry | last post by:
Hi all, I have a datagrid (language C#) populated using a stored procedure. I want one of the column to display complete name instead of abbreviation. Can I change the display dynamically in the...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.