Hi,
I would like to implement similar behaviour to Excel in the XamDataGrid in that if you click on a cell it immediately enters edit mode. Whereas if you hold the mouse down over a cell and drag you do a multiple select of all the cells you drag over.
I get the first behaviour with..<igDP:FieldSettings CellClickAction="EnterEditModeIfAllowed" />
and the second behavior with...<igDP:FieldSettings CellClickAction="SelectCell" />
In addition I have the following settings..<igDP:FieldLayoutSettings SelectionTypeCell="Extended" SelectionTypeRecord="Extended" SelectionTypeField="Extended" />
How can I get both of these behaviours working on the grid. I don't see why this should be impossible as a click on a cell is surely different than a cell selection drag ?
HI,
You could force the cell into edit mode by using a DataPresenterCommand.
Wire up the PreviewMouseLeftButtonDown event.
Here is the code snippet:
void xamgrid1_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { // throw new NotImplementedException(); DependencyObject soruce = e.OriginalSource as DependencyObject; if (soruce == null) return; CellValuePresenter cvp = Infragistics.Windows.Utilities.GetAncestorFromType(soruce, typeof(CellValuePresenter), true) as CellValuePresenter; if (cvp == null) return; cvp.IsActive = true; xamgrid1.ExecuteCommand(DataPresenterCommands.StartEditMode); }
Sincerely, Matt Developer Support Engineer
I am following up on this forum thread.
Do you need further assistance regarding this issue, please let me know
Hi Matt,
I managed to achieve roughly the behaviour I was after but it isn't very satisfactory. I can now....
1. Click and drag the mouse to select multiple cells.
2. Double click on a cell to begin edit
3. Just starting to type on a cell allows you to edit.
4. The arrow keys and tabs keys move between cells and put them into edit mode.
So the user can now select like Excel but have Excel's editing like behaviour. The downside is that when the user selects a cell, it isn't put into edit mode. Yes they can begin typing into it and that will put it into edit mode but there is no visual clue for the user so not great UI.
This technique involved appying the appropriate settings in the XAML for the grid and then handling the CellValuePresenters PreviewKeyDown in the code behind.
Here is the minimal code to achieve this.
From the XAML
<igDP:XamDataGrid Name="grid" BindToSampleData="True"> <igDP:XamDataGrid.Resources> <Style TargetType="{x:Type igDP:CellValuePresenter}"> <EventSetter Event="PreviewKeyDown" Handler="CVP_PreviewKeyDown" /> </Style> </igDP:XamDataGrid.Resources> <igDP:XamDataGrid.FieldLayoutSettings> <igDP:FieldLayoutSettings SelectionTypeCell="Extended" SelectionTypeRecord="ExtendedAutoDrag" SelectionTypeField="Extended" /> </igDP:XamDataGrid.FieldLayoutSettings>
<igDP:XamDataGrid.FieldLayouts> <!-- define a field layout that will match the data --> <igDP:FieldLayout IsDefault="True" > <igDP:FieldLayout.FieldSettings> <igDP:FieldSettings CellClickAction="SelectCell" LabelClickAction="SortByMultipleFieldsTriState"/> </igDP:FieldLayout.FieldSettings> </igDP:FieldLayout> </igDP:XamDataGrid.FieldLayouts></igDP:XamDataGrid>
And from the code behind....
void CVP_PreviewKeyDown(object sender, KeyEventArgs e){ e.Handled = false; if (e.Key != Key.Left && e.Key != Key.Right && e.Key != Key.Tab && Keyboard.Modifiers != ModifierKeys.Control) { CellValuePresenter cvp = (sender as CellValuePresenter); if (null != cvp) { if (e.Key == Key.Up || e.Key == Key.Down) { cvp.EndEditMode(true, true); e.Handled = true; if (e.Key == Key.Up) grid.ExecuteCommand(DataPresenterCommands.CellAbove); else grid.ExecuteCommand(DataPresenterCommands.CellBelow); grid.ExecuteCommand(DataPresenterCommands.StartEditMode); } else { if (!cvp.IsInEditMode) cvp.StartEditMode(); }
} }}
It would be much better if this behaviour was available out the box with the grid rather than having to apply hacks in the codebehind.