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
Thanks, Stefan for all of your help.
Hello Mike,
I have been looking into your code, and I can say that it is a very good approach for achieving the thing you want.
Stefan,
I did manage to get the result I was looking for by trapping the GotFocus message on the grid, and then filtering on the OriginalSource to prevent a stack overflow. Here is my code. Do you think it's ok to take this approach, or is there a better one you can think of?
private void dgExpandedPFT_GotFocus( object sender, RoutedEventArgs e ) { if( e.OriginalSource == this.dgExpandedPFT ) { Record[] records = this.dgExpandedPFT.GetRecordsInView( false ); this.dgExpandedPFT.ActiveRecord = records[ 0 ]; this.dgExpandedPFT.ActiveRecord.DataPresenter.ExecuteCommand( DataPresenterCommands.CellFirstInRecord ); this.dgExpandedPFT.ActiveRecord.DataPresenter.ExecuteCommand( DataPresenterCommands.StartEditMode ); } }
Ah, Stefan - I am fast becomming a fan of yours. Thanks so much, the link gave me what I needed. This, coupled with how I am setting cell editing permissions work together very well and now if a user clicks on cell that is not editable, it goes to the first cell in the row that is editable and I can only tab into cells that are editable. This works really nicely.
I have one last question. My grid is set to tab order 3 and when I tab from the control before it, to the grid, I can see that the entire grid has the focus. What I want is for the tab to go not to the entire grid, but into the first editable cell. How do I do that?
I can suggest you see this forum thread:
http://forums.infragistics.com/forums/t/7243.aspx
where there is a sample (“xamDataGridTabSkip.zip”) with the functionality you want. Please let me know if this helps you or you need further assistance on this matter.
Looking forward for your reply.