472,805 Members | 1,896 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Datagrid and currentcellchanged event

Hi all,

I'm having problems with datagrids and the currentcellchanged event.
My problem is this: I have a datagrid on a form, if the user changes
the text in a cell on the datagrid then tries to close the form via a
button on the toolbar (with going to another cell in the datagrid)I
want to be able to popup a messagebox to the user asking them if they
want to keep their changes.

At the momment I'm accomplishing this by a property that I set to true
in the currentcellchanged event. However if the user just tabs around
the datagrid this event is triggered even though though from the
user's point of view they haven't changed any text.

I still want the user to be able to tab around the datagrid but
perhaps not have the tab key trigger the currentcellchanged event. Is
this possible?

Another way I have thought of doing this is by trying to get the
current datagrid cell's value (using datagrid.text) and then comparing
it to the underlaying datasource's value for that cell (& if the 2 are
different then setting my property to true). However I can't find a
way of getting hold of the datagrid's datasource's value for the
current datagrid cell.

Any ideas would be most gratefully received - one more thing - my
datagrid is a custom control and I would like the above functionality
to be included within the custom control rather than the form that it
sits on.

Thanks in advance for any help
Suzanne
Nov 20 '05 #1
4 7297
Suzanne,
I still want the user to be able to tab around the datagrid but
perhaps not have the tab key trigger the currentcellchanged event. Is
this possible?
You cannot do that, well, unless you don't inherit from DataGrid and tap
into its event handling logic. And I'd say this is not the best way to do
so.
Another way I have thought of doing this is by trying to get the
current datagrid cell's value (using datagrid.text) and then comparing
it to the underlaying datasource's value for that cell (& if the 2 are
different then setting my property to true). However I can't find a
way of getting hold of the datagrid's datasource's value for the
current datagrid cell.
I like this approach much better. And it is relatively simple to get hold of
the corresponding source data row:

CurrencyManager cm = this.BindingContext[dataGrid.DataSource,
dataGrid1.DataMember];
DataView view = (DataView)cm.List;
DataRow theRow = view[dataGrid1.CurrentCell.RowNumber /* -1 probably
*/].Row;

You can then analyze theRow's RowState property to see if it has been
changed.

P.S. I beleive this code can easily be modified to become a part of a custom
DataGrid-based control.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

"Suzanne" <Su***********@mhapensions.com> wrote in message
news:87*************************@posting.google.co m... Hi all,

I'm having problems with datagrids and the currentcellchanged event.
My problem is this: I have a datagrid on a form, if the user changes
the text in a cell on the datagrid then tries to close the form via a
button on the toolbar (with going to another cell in the datagrid)I
want to be able to popup a messagebox to the user asking them if they
want to keep their changes.

At the momment I'm accomplishing this by a property that I set to true
in the currentcellchanged event. However if the user just tabs around
the datagrid this event is triggered even though though from the
user's point of view they haven't changed any text.

I still want the user to be able to tab around the datagrid but
perhaps not have the tab key trigger the currentcellchanged event. Is
this possible?

Another way I have thought of doing this is by trying to get the
current datagrid cell's value (using datagrid.text) and then comparing
it to the underlaying datasource's value for that cell (& if the 2 are
different then setting my property to true). However I can't find a
way of getting hold of the datagrid's datasource's value for the
current datagrid cell.

Any ideas would be most gratefully received - one more thing - my
datagrid is a custom control and I would like the above functionality
to be included within the custom control rather than the form that it
sits on.

Thanks in advance for any help
Suzanne


Nov 20 '05 #2
Can't you use the datarowversion.original from each cell?
Or do I misunderstand the question?
oldvalue= tmprow("fieldname", DataRowVersion.Original)

newvalue=tmprow("fieldname",datarowversion.modifie d)

tmprow is a row in the table where you putted the changes in

Dim updatedrows As DataTable =
dataset1.Tables(0).GetChanges(DataRowState.Modifie d)

Tupolev

"Suzanne" <Su***********@mhapensions.com> schreef in bericht
news:87*************************@posting.google.co m...
Hi all,

I'm having problems with datagrids and the currentcellchanged event.
My problem is this: I have a datagrid on a form, if the user changes
the text in a cell on the datagrid then tries to close the form via a
button on the toolbar (with going to another cell in the datagrid)I
want to be able to popup a messagebox to the user asking them if they
want to keep their changes.

At the momment I'm accomplishing this by a property that I set to true
in the currentcellchanged event. However if the user just tabs around
the datagrid this event is triggered even though though from the
user's point of view they haven't changed any text.

I still want the user to be able to tab around the datagrid but
perhaps not have the tab key trigger the currentcellchanged event. Is
this possible?

Another way I have thought of doing this is by trying to get the
current datagrid cell's value (using datagrid.text) and then comparing
it to the underlaying datasource's value for that cell (& if the 2 are
different then setting my property to true). However I can't find a
way of getting hold of the datagrid's datasource's value for the
current datagrid cell.

Any ideas would be most gratefully received - one more thing - my
datagrid is a custom control and I would like the above functionality
to be included within the custom control rather than the form that it
sits on.

Thanks in advance for any help
Suzanne

Nov 20 '05 #3
Thanks for all the suggestions, unfortunately it's still not behaving
exactly as I'd planned...

I'm unable to use the versioning mechanism Mr. Tupolev suggests as
when the user clicks on the toolbar (with the focus still being in the
edited cell of the datagrid) I don't think that the underlying
datatable has yet been updated with any changes? Which is really the
whole problem!

Dmitriy's suggestions for using the currency manager to get the
corresponding source data row were alot closer to what I was looking
for (and does return this value) - however I was planning to check the
value of underlaying datasource's value for that cell against the new
text of the datagrid cell when the currentcellchanged event was
triggered.

The problem is that this event is trigged as soon as the user tabs
into the cell and then I guess for every keystroke afterwards? So I
don't know when my user has finshed editing the cell (if it is the
custom control datagrid that is handling this functionality rather
than the form it sits on).

The solution that I'm using - which works - but is not pretty - is
that in the code for my form, when the user clicks on the toolbar I
run a bit of code that sets the currentcell of my datagrid to the 1st
cell in the grid (if the user is not currently editing the first cell,
if they are then I set the current cell to be another cell). Basically
I just force the datagrid to update its datasource by moving out of
the edited cell, so I don't need to use the currentcellchanged event
at all.

If any one can think of a more elegant way to do this then I'd be most
interested

Again thanks for all the help

Suzanne
Nov 20 '05 #4
Hi Susanne,

Have you tried using the aftercoledit event. It might do what you want. If
nothing has been changed, the event won't fire.

Suzette

"Suzanne" <Su***********@mhapensions.com> wrote in message
news:87*************************@posting.google.co m...
Hi all,

I'm having problems with datagrids and the currentcellchanged event.
My problem is this: I have a datagrid on a form, if the user changes
the text in a cell on the datagrid then tries to close the form via a
button on the toolbar (with going to another cell in the datagrid)I
want to be able to popup a messagebox to the user asking them if they
want to keep their changes.

At the momment I'm accomplishing this by a property that I set to true
in the currentcellchanged event. However if the user just tabs around
the datagrid this event is triggered even though though from the
user's point of view they haven't changed any text.

I still want the user to be able to tab around the datagrid but
perhaps not have the tab key trigger the currentcellchanged event. Is
this possible?

Another way I have thought of doing this is by trying to get the
current datagrid cell's value (using datagrid.text) and then comparing
it to the underlaying datasource's value for that cell (& if the 2 are
different then setting my property to true). However I can't find a
way of getting hold of the datagrid's datasource's value for the
current datagrid cell.

Any ideas would be most gratefully received - one more thing - my
datagrid is a custom control and I would like the above functionality
to be included within the custom control rather than the form that it
sits on.

Thanks in advance for any help
Suzanne

Nov 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: amber | last post by:
Hello, How can I trigger an event, when a value (cell) in my datagrid changes? TIA, amber
2
by: PAUL GROSSMAN | last post by:
Hello everyone. I am working with a DataGrid using VB .Net (Windows Forms). I want to make one of the columns un-editable. I was able to do that by setting the ...
1
by: Lester Moreno | last post by:
Hello all, I'm trying to find a way to get a event raised when you change some text on a DataGrid Cell, I need to be able to search in another table what the user typed on that cell. I found...
4
by: John Smith | last post by:
Hey folks, Is there a way to make the data grid always select a row only and not an individual cell? Like...When I click on the row header it highlights the whole row in blue. But when I then...
1
by: GregM | last post by:
I have a read only datagrid that is designed to coordinate itself with textboxes. When the user clicks on a row in the datagrid, detailed data for that row is displayed for editing in the...
3
by: Maqsood Ahmed | last post by:
Hello, Here is the scenario: I have a datagrid on a winform and a datatable is set as its datasource. I have added DataGridTableStyle in datagrid's TableStyles property. Some of Gridstyles are...
4
by: Roger | last post by:
I have a datagrid and would like to know what even fires when a cell is changed? I want to know when the user changes a cell and moves to the next. I have some code that needs to be done to...
5
by: Earl | last post by:
I want to fire a database update off of a single change to a single cell in the datagrid. This apparently cannot be done using keypress, keyup, keydown, etc. I've read George Shepard's FAQ and...
5
by: cj | last post by:
This should be easy. I have a datagrid filled with data and when I click on a cell I want that data displayed in a text box. How do I do this? Thanks. P.S. this is a 2005 windows app.
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Sept 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.