We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Blanking a DateTime value from GridDataBoundGrid

Thread ID:

Created:

Updated:

Platform:

Replies:

46301 Jul 10,2006 02:26 PM Jul 14,2006 08:31 AM Windows Forms 9
loading
Tags: GridControl
John Patterson
Asked On July 10, 2006 02:26 PM

Hello. I am having some difficulty determining the appropriate process for "deleting" a DateTime value from a grid. I would like some assistance. I have created a GridDataBoundGrid and added a series of GridBoundColumns to the GridBoundColumns collection of the grid. One of my columns is defined with a CellValueType of "System.DateTime". I am binding the grid to a collection of custom objects, on which there is a property corresponding to the DateTime bound column. I want to be able to allow users of the grid to press the "Delete" key and convert the value of the column from a valid date to DateTime.MinValue; this "blanks out" the value on the display and allows the grid to parse the input to an appropriate data type. I am currently implementing the "CurrentCellKeyDown" event, which allows me to trap for the Delete key and replace the contents of the grid with the DateTime.MinValue as desired. However, I have the following scenarios. When I set the value of the column to a valid DateTime value, and move to a different row, the entered DateTime value is persisted through the Model to the underlying data source (due to the "RowSaved" event being fired). I can then move back to the original row, press the Delete key, and the value is replaced with DateTime.MinValue, as expected. If I set the value of the column to a valid DateTime value, and move to a different cell, but remain in the same row, the DateTime value is accepted. If I move back to the DateTime column and press the Delete key, the value is seemingly blanked out (as evidenced when I debug the process), but the moment I move to another row or even a different cell in the same row, the original DateTime value returns and is displayed. I feel that this is a consequence of how changes are saved to a row cache and subsequently pushed through to the underlying model, but I do not understand what is preventing my changes from persisting to the model. I have tried explicitly executing "grid.CurrentCell.EndEdit" followed by "grid.Binder.EndEdit", but the MinValue is not persisted to the model - it always reverts if a RowSave has not yet occurred. My grid is also set as "EnableRemove = false", which is why I had to implement the "CurrentCellKeyDown" event (I believe). I am using Syncfusion 3.301.0.11. Any help you can give is appreciated.

Administrator [Syncfusion]
Replied On July 10, 2006 05:32 PM

Hi John, I have created a sample as per your specification. The sample illustrates the possiblity to set the DateTime.MinValue when the Delete key is pressed in a bound cell . Please refer to the attached sample and let us know if you are trying something different. Here is a sample. http://www.syncfusion.com/Support/user/uploads/GDBGValid_e5c80852.zip Best Regards, Haneef Note : You need to set the GridBoundColumn''s StyleInfo''s Format property to "dd/mm/yyyy".

John Patterson
Replied On July 11, 2006 08:29 AM

Hi Haneef, Thanks for your response. I have implemented my grid and handlers in the same manner that you''ve indicated in the sample. The sample behaves like the code that I''ve been working with, which unfortunately does not solve my issue. When the grid in the sample is loaded, it contains valid DateTime values in the specified column. If the DateTime value (DateTime A) is modified to another valid DateTime value (DateTime B), and the CurrentCell is moved to another cell in the same row, the newly entered DateTime value (DateTime B) remains in the cell. If the CurrentCell is moved back to the DateTime column, and the Delete key is pressed, the DateTime value (DateTime B) changes to "01/00/0001" (DateTime X) as expected. However, the moment the CurrentCell is moved to another cell in the same row, or even to a different row entirely, the value changes to the previous DateTime value (DateTime B) and the "deleted" DateTime value is no longer contained in the cell. Now, if I move the CurrentCell back to the DateTime column, and press Delete, the DateTime value (DateTime B) is changed to "01/00/0001" (DateTime X) and the value will remain as I move through the grid. It seems as if the grid is maintaining the modification from "DateTime A" to "DateTime B" as a pending change, and the act of "deleting" the DateTime to overwrite it with "01/00/0001" does not update the segment which contains the pending changes. Please let me know if any further clarification of my issue is required. Thanks for your assistance. >Hi John, > >I have created a sample as per your specification. The sample illustrates the possiblity to set the DateTime.MinValue when the Delete key is pressed in a bound cell . Please refer to the attached sample and let us know if you are trying something different. > >Here is a sample. >http://www.syncfusion.com/Support/user/uploads/GDBGValid_e5c80852.zip > >Best Regards, >Haneef > >Note : You need to set the GridBoundColumn''s StyleInfo''s Format property to "dd/mm/yyyy".

Administrator [Syncfusion]
Replied On July 11, 2006 12:32 PM

Hi John, Try this code to resolve the mentioned issue. Here is a code snippet. GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell; if( e.KeyCode == Keys.Delete && ! cc.IsEditing ) { this.gridDataBoundGrid1.BeginUpdate(); this.gridDataBoundGrid1.Binder.SuspendBinding(); CurrencyManager cm = this.BindingContext[ this.gridDataBoundGrid1.DataSource] as CurrencyManager; DataRowView drv = cm.Current as DataRowView; drv.Row["Date"] = DateTime.MinValue; this.gridDataBoundGrid1.Binder.ResumeBinding(); this.gridDataBoundGrid1.EndUpdate(true); e.Handled = true; } Let me know if this helps. Best Regards, Haneef

John Patterson
Replied On July 11, 2006 04:08 PM

Hi Haneef, I have implemented the supplied code snippet, using the CurrencyManager to get a handle to my object to update the underlying source value. When I step through, I see that the code to enter the DateTime.MinValue is being executed, and the underlying value is changed, but the grid does not update to reflect this. Using this approach, the changed value is not even deleted from the grid cell - it simply remains as entered. When moving off the target row to a different row, the changed value remains. If I go back to the target row, and then hit the "Delete" key, the value deletes as expected. I even tried a few different methods (e.g. gridDataBoundGrid1.Refresh(), gridDataBoundGrid1.Invalidate()) in the hopes that it was simply due to the UI not receiving a notification to repaint. Neither method provided me with a solution. Any other possibilities? >Hi John, > >Try this code to resolve the mentioned issue. Here is a code snippet. > >GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell; >if( e.KeyCode == Keys.Delete && ! cc.IsEditing ) >{ > this.gridDataBoundGrid1.BeginUpdate(); > this.gridDataBoundGrid1.Binder.SuspendBinding(); > > CurrencyManager cm = this.BindingContext[ this.gridDataBoundGrid1.DataSource] as CurrencyManager; > DataRowView drv = cm.Current as DataRowView; > drv.Row["Date"] = DateTime.MinValue; > > this.gridDataBoundGrid1.Binder.ResumeBinding(); > this.gridDataBoundGrid1.EndUpdate(true); > e.Handled = true; >} > >Let me know if this helps. >Best Regards, >Haneef

Administrator [Syncfusion]
Replied On July 11, 2006 05:13 PM

Hi John, Please send us the screen shot or sample with the issue, it will helpful to trace the problem exactly. Attached sample working fine here. Could you please try running the same at your end and send me back the modified sample if still the problem exists? Also please let me know about the current version of Essential Studio/.Net FrameWork/OS you are using. Here is a sample. http://www.syncfusion.com/Support/user/uploads/GDBGValid_61fc5185.zip Thanks for your patience. Best Regards, Haneef

John Patterson
Replied On July 12, 2006 08:38 AM

Hi Haneef, Before I upload any screenshots, please follow these steps in the below scenarios to duplicate the issue that I am describing. Attaching a sample will, in all likelihood, not provide any information, because I have implemented as specified per your instructions. The issue that I''m describing occurs in my code as well as in the sample that has been provided. The following scenarios use the sample that has been provided via this forum thread. Scenario 1 This scenario exhibits the proper, expected behavior. 1. Run the sample so that the default values are loaded into the form. 2. Use the tab or arrow keys to move the CurrentCell to the last cell of the first row, which is the DateTime column in question. This will highlight the DateTime cell and keep the cell from entering Edit mode. 3. Hit the Delete key. The initial DateTime value is replaced with DateTime.MinValue, as expected. There are no further actions required. Scenario 2 This is the issue that I''m experiencing, and this issue is also present in the provided sample. 1. Run the sample so that the default values are loaded into the form. 2. Use the tab or arrow keys to move the CurrentCell to the last cell of the first row, which is the DateTime column in question. This will highlight the DateTime cell and keep the cell from entering Edit mode. 3. Enter another valid DateTime value into the target DateTime cell. This will modify the default to a new valid value. 4. After successfully entering a new DateTime value, move the CurrentCell to another cell in the same row, but remain in the current row (this prevents the RowSave event from executing). 5. Move the CurrentCell back to the last column in the row with the modified value. Use the tab or arrow keys to prevent the cell from entering Edit mode. 6. Press the Delete key. (Note: A breakpoint in the "CurrentCellKeyDown" method will show that the necessary code is executed at this point). 7. The DateTime value does NOT change to DateTime.MinValue. It remains as the modified value, which was entered in step 3. This is the issue I am trying to account for. 8. Navigate from the modified row to another row in the grid. Please note that the modified value still exists in the cell which was changed. 9. Navigate back to the cell with the modified value. Press the Delete key. The modified value is now replaced with DateTime.MinValue, as expected. The current versions that I''m using are: Syncfusion : 3.301.0.11 .NET: v1.1.4322 OS: Windows XP Pro with SP2 After examining this, please let me know if you would still like me to post a sample. I have the code from the sample directly pasted into my module, and the behavior I encounter mimics that of the sample. Thanks for continued efforts. >Hi John, > >Please send us the screen shot or sample with the issue, it will helpful to trace the problem exactly. Attached sample working fine here. Could you please try running the same at your end and send me back the modified sample if still the problem exists? Also please let me know about the current version of Essential Studio/.Net FrameWork/OS you are using. > >Here is a sample. >http://www.syncfusion.com/Support/user/uploads/GDBGValid_61fc5185.zip > >Thanks for your patience. >Best Regards, >Haneef >

Administrator [Syncfusion]
Replied On July 13, 2006 01:03 AM

Hi John, Sorry for the inconvenience caused. Thanks for your more information. I am able to reproduce the issue here. Could you try this code snippet to resolve this issue. Please find the code snippet here. GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell; if( e.KeyCode == Keys.Delete && ! cc.IsEditing ) { this.gridDataBoundGrid1.Binder.BeginEdit(); cc.BeginEdit(true); cc.EndEdit(); this.gridDataBoundGrid1.Model[cc.RowIndex,cc.ColIndex].CellValue = DateTime.MinValue; cc.EndEdit(); this.gridDataBoundGrid1.Binder.EndEdit(); e.Handled = true; } Let me know if i am missing something. Best Regards, Haneef

John Patterson
Replied On July 14, 2006 08:27 AM

Hi Haneef, The solution you provided does indeed resolve the Delete problem I was experiencing. Thanks! One new item though. Now that the delete works, the current cell gets "stuck" on the cell which had the deleted value, so long as the row is not changed (and thus RowSaved is not executed). It takes two keystrokes (either arrow key or tab key) to navigate out of the cell after a delete has been executed. However, once moving to a new row and then back again, the navigation behaves as it should. Any idea on what might be causing the current cell to get "stuck" momentarily on the cell which contained the value which was just deleted? Thanks for any additional info you can provide. And thanks for the help with the Delete! >Hi John, > >Sorry for the inconvenience caused. > >Thanks for your more information. I am able to reproduce the issue here. Could you try this code snippet to resolve this issue. Please find the code snippet here. > >GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell; >if( e.KeyCode == Keys.Delete && ! cc.IsEditing ) >{ > this.gridDataBoundGrid1.Binder.BeginEdit(); > cc.BeginEdit(true); > cc.EndEdit(); > this.gridDataBoundGrid1.Model[cc.RowIndex,cc.ColIndex].CellValue = DateTime.MinValue; > cc.EndEdit(); > this.gridDataBoundGrid1.Binder.EndEdit(); > e.Handled = true; >} > >Let me know if i am missing something. >Best Regards, >Haneef

John Patterson
Replied On July 14, 2006 08:31 AM

Hi Haneef, Please disregard that last post. I had some residue code that was causing the navigation issues. I removed the code items and the navigation problems went away. The solution you provided works as advertised. Thanks for the help! >Hi Haneef, > >The solution you provided does indeed resolve the Delete problem I was experiencing. Thanks! > >One new item though. Now that the delete works, the current cell gets "stuck" on the cell which had the deleted value, so long as the row is not changed (and thus RowSaved is not executed). It takes two keystrokes (either arrow key or tab key) to navigate out of the cell after a delete has been executed. However, once moving to a new row and then back again, the navigation behaves as it should. > >Any idea on what might be causing the current cell to get "stuck" momentarily on the cell which contained the value which was just deleted? > >Thanks for any additional info you can provide. And thanks for the help with the Delete! > >>Hi John, >> >>Sorry for the inconvenience caused. >> >>Thanks for your more information. I am able to reproduce the issue here. Could you try this code snippet to resolve this issue. Please find the code snippet here. >> >>GridCurrentCell cc = this.gridDataBoundGrid1.CurrentCell; >>if( e.KeyCode == Keys.Delete && ! cc.IsEditing ) >>{ >> this.gridDataBoundGrid1.Binder.BeginEdit(); >> cc.BeginEdit(true); >> cc.EndEdit(); >> this.gridDataBoundGrid1.Model[cc.RowIndex,cc.ColIndex].CellValue = DateTime.MinValue; >> cc.EndEdit(); >> this.gridDataBoundGrid1.Binder.EndEdit(); >> e.Handled = true; >>} >> >>Let me know if i am missing something. >>Best Regards, >>Haneef

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;