I have a data grid where certain cells should not be editable.
When the grid first draws, I have three rows of data and some cells can be edited, and some not. Then I have a button where I add a an object to the ObservableCollection populating the list, and in this case sometimes a cell should have its editing turned off.
How do I do this in the code behind?
Thanks.
Mike
Stefan,
Thanks for that. On another issue my client says that he wants tabbing behavior to work so that the users can only tab to a cell that is editable. I've trapped the PreviewKeyDown message and have managed to know when the tab key has been pressed and I can find the row and column positions of the cell.
I have two questions, first how do I set an active cell? If I know that the next editible cell is on the same row, but two cells over, how do I position them there?
The second question is about how the grid behaves when tabbing. I have the tab order on the grid set to 3, and yet when I start tabbing through controls, it seems to skip over the grid and won't tab into it. How do I make that happen?
Thanks again for all of your help.
Mike.
Hello Mike,
I have been looking into your code and I can say that this way you make all the Cells in a particular Field Editable or not, by setting the Field’s AllowEdit Property, but if it works for your scenario, I don’t see any reason why not to use it instead of the approach I gave you.
Hope this helps you.
Thanks for doing this. What I wound up doing yesterday was to trap the CellActivated message and then grabbed the record index and set the AllowEdit property to true or false for the row. I'll look at what you did and was wondering if that is a better way than this:
private void dgExpandedPFT_CellActivated( object sender, Infragistics.Windows.DataPresenter.Events.CellActivatedEventArgs e ) { switch( e.Cell.Record.Index ) { case 0: { this.dgExpandedPFT.Records[ e.Cell.Record.Index ].FieldLayout.Fields[ 3 ].Settings.AllowEdit = false; this.dgExpandedPFT.Records[ e.Cell.Record.Index ].FieldLayout.Fields[ 4 ].Settings.AllowEdit = false; this.dgExpandedPFT.Records[ e.Cell.Record.Index ].FieldLayout.Fields[ 5 ].Settings.AllowEdit = false; this.dgExpandedPFT.Records[ e.Cell.Record.Index ].FieldLayout.Fields[ 6 ].Settings.AllowEdit = true; this.dgExpandedPFT.Records[ e.Cell.Record.Index ].FieldLayout.Fields[ 7 ].Settings.AllowEdit = true; this.dgExpandedPFT.Records[ e.Cell.Record.Index ].FieldLayout.Fields[ 8 ].Settings.AllowEdit = false; this.dgExpandedPFT.Records[ e.Cell.Record.Index ].FieldLayout.Fields[ 9 ].Settings.AllowEdit = false; break; } case 1: { this.dgExpandedPFT.Records[ e.Cell.Record.Index ].FieldLayout.Fields[ 3 ].Settings.AllowEdit = false; this.dgExpandedPFT.Records[ e.Cell.Record.Index ].FieldLayout.Fields[ 4 ].Settings.AllowEdit = false; this.dgExpandedPFT.Records[ e.Cell.Record.Index ].FieldLayout.Fields[ 5 ].Settings.AllowEdit = false; this.dgExpandedPFT.Records[ e.Cell.Record.Index ].FieldLayout.Fields[ 6 ].Settings.AllowEdit = true; this.dgExpandedPFT.Records[ e.Cell.Record.Index ].FieldLayout.Fields[ 7 ].Settings.AllowEdit = true; this.dgExpandedPFT.Records[ e.Cell.Record.Index ].FieldLayout.Fields[ 8 ].Settings.AllowEdit = true; this.dgExpandedPFT.Records[ e.Cell.Record.Index ].FieldLayout.Fields[ 9 ].Settings.AllowEdit = true; this.dgExpandedPFT.Records[ e.Cell.Record.Index ].FieldLayout.Fields[ 10 ].Settings.AllowEdit = false; break; } default: { this.dgExpandedPFT.Records[ e.Cell.Record.Index ].FieldLayout.Fields[ 3 ].Settings.AllowEdit = true; this.dgExpandedPFT.Records[ e.Cell.Record.Index ].FieldLayout.Fields[ 4 ].Settings.AllowEdit = true; this.dgExpandedPFT.Records[ e.Cell.Record.Index ].FieldLayout.Fields[ 5 ].Settings.AllowEdit = true; this.dgExpandedPFT.Records[ e.Cell.Record.Index ].FieldLayout.Fields[ 6 ].Settings.AllowEdit = true; this.dgExpandedPFT.Records[ e.Cell.Record.Index ].FieldLayout.Fields[ 7 ].Settings.AllowEdit = true; this.dgExpandedPFT.Records[ e.Cell.Record.Index ].FieldLayout.Fields[ 8 ].Settings.AllowEdit = true; this.dgExpandedPFT.Records[ e.Cell.Record.Index ].FieldLayout.Fields[ 9 ].Settings.AllowEdit = true; this.dgExpandedPFT.Records[ e.Cell.Record.Index ].FieldLayout.Fields[ 10 ].Settings.AllowEdit = true; break; } } }
What do you think?
Thanks,
I have been looking into you requirement and I created a sample project for you with the functionality you want. Basically the whole XamDataGrid is editable, but I handled the EditModeStarting event and canceled it if a certain condition is met. Please let me know if this helps you or you need further assistance on this matter.
Looking forward for your reply.
Thanks for helping with what message I want to trap. But, how do I prevent editing in a particular cell? My customer wants to turn editing on or off at a particular cell, as some cells in a column may be editable or not based on what is in the row.
So, given a data grid, how do I manage to prevent editing at the cell level?