I used dattriggers in the XamDataGrid for WPF but could not use
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
in the XamGrid. Are there any plans to allow datatriggers in the XamGrid? I wanted to allow or disallow editing of cells based a condition of the data and had to use the ActiveCellChanging and CellEnteringEditMode events to prevent editing of a cell based on a data condition. By the way, setting e.cancel = true in the ActiveCellChanging event did not prevent the cell from Activating, I also had to trap in the CellEnteringEditMode event.
Hello drdonna,
I was looking into your questions, and I can see the issue you are describing. Still please have in mind that the using of a DataTrigers is a Silverlight limitation, so their support isn’t currently built in our XamGrid. However after some investigation of the issue I believe that the functionality you are requiring can be achieved by handling the CellClicked event of the XamGrid and change the AllowEdit property of the control from the handler:
private void xamGrid_CellClicked(object sender, CellClickedEventArgs e)
{
if(e.Cell.Value....)
xamGrid.EditingSettings.AllowEditing = EditingType.None;
else
xamGrid.EditingSettings.AllowEditing = EditingType.Cell;
}
If you need any further assistance on this matter, please feel free to ask.
Thank you for helping me with my issue. While your answer does prevent editing it does it at the grid level which is too big a scope. There are other fields that are still editable and I would need to intercept for every editable cell and make sure editing was turned on.
Here is how I accomplished what I needed. I though that cancelling in the ActiveCellChanging event would work but canceling the CellEnteringEditMode seems to do the trick.
private void TimeTransferDataGrid_CellEnteringEditMode(object sender, BeginEditingCellEventArgs e) { // If logged in user is not the subject of the transfer do not allow them to edit these columns if (e.Cell != null && (e.Cell.Column.Key == "ReasonCode" || e.Cell.Column.Key == "ReasonDescription")) { if (MainPage.CurrentAppUser.EmpCode != e.Cell.Row.Cells["EvcCode"].Value.ToString()) { e.Cancel = true; } // If reject flag has been choosen do not allow entry if (e.Cell.Row.Cells["RejectTransfer"].Value.ToString() == "1" || e.Cell.Row.Cells["ApproveTransfer"].Value.ToString() == "0") { e.Cancel = true; } } }
I am really glad that you managed to resolve your issue. If you need any further assistance on the matter, please do not hesitate to ask.
I have something kind of related. On a grid row if a user clicks "Accept" for a time transfer they are required to choose a reason code from a drop down combo box in the next cell to the Accept checkbox cell. I don't want the user to be able to remove focus from the grid row until they also pick a reason code from the combo editor. I have not been able to force the grid to stay on the row. I see editing examples for a single field being a specific value but what about other required fields on the same grid row?
I get around this by using a Childwindow but would rather force the user to stay on a grid row until all required data has been entered. Even though it is not an error until they try and move off the row without picking a value, I could set an error state on the row after "Accept" has been clicked even though they have not had a chance to pick a value yet? Maybe this would keep the focus on the row until the value was chosen?
I have used the SelectedRowsCollectionChanged event and messed with the PeviouslySelectedItems and NewSelectedItems but cannot keep focus on the grid row that is not complete. It puts the grid into a funky state where moving the cursor selects cells and rows that are hovered over by the cursor. I may be able to create a sample when I have some time. I am supposed to be doing testing this week and since I have a work around we will see if this is acceptable to the users.
I was looking into your requirements and I believe that the functionality you are describing can be achieved by implementing IDataErrorInfo on your business objects in order to set a validation rule as it is shown in the following link form our sample browser:
http://samples.infragistics.com/sllob/RunSamples.aspx?cn=grid#/grid/idataerrorinfo
In addition you can set AllowEditng=”Row”, so the focus can stay on the row and move into its cells even when some of them have an error:
http://samples.infragistics.com/sllob/RunSamples.aspx?cn=grid#/grid/editing-data
If you require any additional assistance on this, please feel free to ask.
Thanks for the ideas maybe the combination of the two will give me what I want. I will give it a try and let you know. At one point I had the AllowEdit scope at Row and changed it to Cell and maybe that change is the problem.
Thank you for getting back to me. If you have any further questions or concerns on this matter, please do not hesitate to ask.