Hi,
I want to make perticular unbound cell editable when i double click on that cell.
By default AllowEdit is true for unbound field.
That is at Field level.
I am setting AllowEdit to false intially as i dont want user to allow edit unless he double clicks on cell.
When user double clicks on cell and if i set AllowEdit to true then it makes all the columns editable which i dont want.
If on double click if i set IsEnabled to true or ISReadOnly to false it does not go in edit mode as initially i have set AllowEdit to false on Field level.
IS there any way to handle this scenario?
Timely response would be appriciated. As last time when i had support qury they reverted after about an month
Hello Rony,
Thank you for your post!
To start, I would recommend handling two events, the EditModeStarting event on the XamDataGrid, which is cancellable, and the MouseDoubleClick event through an EventSetter in a Style for CellValuePresenter, which you can then apply to your unbound field’s CellValuePresenterStyle property. You will also want to have the AllowEdit property on your unbound field set to “True.” Finally, you will need to add an extra property to your underlying data item that determines whether each cell can be edited or not. I would recommend a bool property for this.
The EditModeStarting event of the XamDataGrid will fire when every cell in the XamDataGrid is starting edit mode, but this event can be cancelled. From the event arguments of this event, you can retrieve the cell that is about to start edit mode, and by using CellValuePresenter.FromCell(Cell c), you can obtain the CellValuePresenter that presents that particular cell. From this CellValuePresenter, you can check the Field that the cell belongs to, and if that field is your unbound field, you can obtain the record and its data item from the CellValuePresenter as well by using CVP.Record.DataItem. This is where that extra bool property mentioned above comes in. You can check that property on the data item of that particular record to tell if the event should be cancelled or not. For example, if the data items property is false, you can call e.Cancel = true and the cell will not go into edit mode. If not, the beginning of edit mode on that particular cell will continue.
The MouseDoubleClick event from the CellValuePresenter style is where this extra bool property can be set. When this event fires, you can cast the sender of the event to a CellValuePresenter object and retrieve the data item from its record as before. Then, you can check that data item’s current value and set it to the value that allows the start of edit mode in the EditModeStarting event.
I have attached a sample project to demonstrate the above. For clarity of which cells are editable and which aren’t, when a cell becomes editable in the unbound “ID” field, it will have a light blue background color.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate DeveloperInfragistics Inc.www.infragistics.com/support
Hi, Thanks for the reply. Was able to get it working as per my scenario after refering demo code that you have provided.
Is there a way to to set move focus away from the currently editable cell to next cell once user has finished entering the value.
Thanks,
I have updated my sample application that I had originally sent you to also handle the EditModeEnded event on the XamDataGrid. In this event, you can call MyXamDataGrid.ExecuteCommand(DataPresenterCommands.CellNextByTab). This move focus to the next cell by tab order, and if this cell is editable, it will enter edit mode on that cell. The updated sample is attached.