Ok. I've create a simple DataGridView via the wizard in VS 2008 and every thing works fine. But now I wish to have one column, to display the last edit date (or create new date). So somehow I would like to have Date.Now insert automaticly, but how? In Form.Load, in DataSet or in Database. And how should the code look like?
Thanks. |
| thek1907 Monday, July 20, 2009 6:40 PM |
I started looking at this in more detail to try to help and there are just *too* manychoices. It really depends on what you need to do. But you can focus on the DataGridView events. If you want to set the date on the update of any cell, you could set the date in the CellValueChanged event. If you have lots of cells, this will update on every cell change, which may or may not be a problem for you. CurrentCellDirtyState changed is another option. It will also occur on every cell change. If you want it to happen only one time per row, there is a RowValidating. But it does not occur until after the user leaves the row. So you may want to look through the DataGridView events, put in some break points, and see where it makes the most sense for your application to update the date/time value. But what if the user changes a cell and then changes it back. Did you want your row in your database to be updated to the new date in this case? Another option is to not show the edit date in the grid and rather set it in code just before saving the data. (I know the next logical question is to ask how to do this. I don't use tableadapters so I really don't know. Can you just update the DataSet fields before calling the Updatexxx method?) This way you won't have any date changes when there was no data change. Hope this helps. www.insteptech.com ;
msmvps.com/blogs/deborahk
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS! - Marked As Answer bythek1907 Monday, July 20, 2009 8:02 PM
-
|
| DeborahK Monday, July 20, 2009 7:53 PM |
There are many different ways to accomplish this. If you want to provide sorting of this column, it would be easiest to add the column to the underlying datasource, which I assume is your DataSet? Hope this help. www.insteptech.com ;
msmvps.com/blogs/deborahk
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS! |
| DeborahK Monday, July 20, 2009 6:50 PM |
There are many different ways to accomplish this.
Will you show me one? :) And yes, my underlying datasource is my DataSet. |
| thek1907 Monday, July 20, 2009 6:51 PM |
MyDataSet.Tables(0).Columns.add("LastEditDate") The above code will add a column to your table. You may then want to adjust the properties of that column to ensure it is treated like a date. Hope that helps. www.insteptech.com ;
msmvps.com/blogs/deborahk
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS! |
| DeborahK Monday, July 20, 2009 7:06 PM |
Maybe I wasn't clear (and sorry about that)
But I have the "LastEditDate" column already. I just want to "auto insert todays date" in the "LastEditDate" column, when I click in the GridView to edit a row or to add a new. So everytime I do this, the "Todays date" should be inserted automaticly. (in the "LastEditDate" column)
Thanks for your quick replys, DeborahK |
| thek1907 Monday, July 20, 2009 7:11 PM |
Are you using a bindingSource? Or just binding the DataGridView directly to the DataSet? www.insteptech.com ;
msmvps.com/blogs/deborahk
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS! |
| DeborahK Monday, July 20, 2009 7:21 PM |
BindingSource. (It's auto-created when using the wizard) |
| thek1907 Monday, July 20, 2009 7:22 PM |
Sorry, one more question. Did you mention what language you are using? www.insteptech.com ;
msmvps.com/blogs/deborahk
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS! |
| DeborahK Monday, July 20, 2009 7:33 PM |
Don't be sorry - It's a excellent service you have ;-)
It's vb.net (framework 3.5) |
| thek1907 Monday, July 20, 2009 7:37 PM |
I started looking at this in more detail to try to help and there are just *too* manychoices. It really depends on what you need to do. But you can focus on the DataGridView events. If you want to set the date on the update of any cell, you could set the date in the CellValueChanged event. If you have lots of cells, this will update on every cell change, which may or may not be a problem for you. CurrentCellDirtyState changed is another option. It will also occur on every cell change. If you want it to happen only one time per row, there is a RowValidating. But it does not occur until after the user leaves the row. So you may want to look through the DataGridView events, put in some break points, and see where it makes the most sense for your application to update the date/time value. But what if the user changes a cell and then changes it back. Did you want your row in your database to be updated to the new date in this case? Another option is to not show the edit date in the grid and rather set it in code just before saving the data. (I know the next logical question is to ask how to do this. I don't use tableadapters so I really don't know. Can you just update the DataSet fields before calling the Updatexxx method?) This way you won't have any date changes when there was no data change. Hope this helps. www.insteptech.com ;
msmvps.com/blogs/deborahk
We are volunteers and ask only that if we are able to help you, that you mark our reply as your answer. THANKS! - Marked As Answer bythek1907 Monday, July 20, 2009 8:02 PM
-
|
| DeborahK Monday, July 20, 2009 7:53 PM |
But what if the user changes a cell and then changes it back. Did you want your row in your database to be updated to the new date in this case?
I know the next logical question is to ask how to do this?
Hope this helps.
Every time a cell changes a "new" date-timestamp is requirred Yes, that's my next question. ;-) I'll try toupdate the DataSet fields before calling the Update method And Yes, this helped me a lot. Thanks !!! |
| thek1907 Monday, July 20, 2009 8:02 PM |