This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hello I'm binding a DataTable to the DataGrid and using OnValidateCell to set the validation state for each cell. When one value is changed by the user I need to validate all the values in the DataTable and thereby update the validation state of each cell. To accomplish this what I currently do is detect when a change happens in the DataTable. Next I validate the entire DataTable and use DataTables built in columnerror/rowerror to record the error a cell has. Then I set the DataGrid binding to "null" followed by rebinding it to the DataTable which has been validated (reload DataTable). This triggers the OnValidateCell for all the cells and I can update the cell validation state. The problem is that when the user goes from one cell to the next to edit the value the rebinding causes the focus on the new cell to be lost. Causing the user to click a second time to enter edit mode in the cell. (I'm using CellEditModeBehavior="OnClick") This off course is cause by the rebinding. How can I avoid the click twice to enter edit mode? Just thinking out loud the following may help if it's available:
Thanks Oscar P.S. The override for OnValidateCell looks like this:
|
|
|
Hi Oscar, The best solution I can provide is adding a method called UpdateAllCellValidation to the DataGrid which will cause the validation state of all visible cells to be rechecked in the usual way. This is far better than needing to rebind the entire items source. This method will be available in the next nightly build. -Jason Fauchelle |
|
|
Thanks Jason. As always you responded promptly. I tried the new method and it works great! I debated as to how to call the UpdateAllCellValidation method from the ViewModel. This is what I did. Since we have a class derive from the DataGrid (i.e. public class MyDataGrid : DataGrid) I added a DependencyProperty
where
In the viewmodel I put a property "TriggerAllCellValidation" which I bind to the DependencyProperty "TriggerAllCellValidation".
Hence in the viewmodel all you need to do is TriggerAllCellValidation = true; and the method is called. The ViewModel property first set the value "true" and then resets it to false. So only the "true" value would trigger the call to the UpdateAllCellValidation(). What is your opinion on this approach? Do you have another approach which would also work? . . . Oscar |
|
|
Hi Oscar, Another possible way to do this could be when certain actions are performed within your custom class that derives from DataGrid. For example, maybe your custom DataGrid could attach handlers to the DataTable to listen to when values change, which could then trigger the request to update all cell validation. If it is not possible to perform all the logic within your DataGrid class for updating the validation, then the solution you have described is good, and probably what I would have done too. -Jason Fauchelle |
|