Hello,
I want to do simple selection in xamdatagrid like in excel. I want to, if a key is pressed down (like shift or control)
to select the records I want by clicking on a cell in the rows I am interested in and select all records and these should be marked and be in the SelectedItems collection. The last row I clicked must be the active row or record.
The style of the selected rows should be clear and easy to see, could somebody provide me with a code sample in C#?
I am using a base class which customizes XamDataGrid and want to be able to do this programmatically.
You can traverse the app visual tree and see what presenter you ca clicking on. You can try something like this:
void xamDataGrid1_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
CellValuePresenter cvp = Infragistics.Windows.Utilities.GetAncestorFromType(
e.OriginalSource as DependencyObject,
typeof(CellValuePresenter),
false) as CellValuePresenter;
if (e != null)
MessageBox.Show(cvp.ToString());
}
Did you ever figure out how to determine the Current Cell while the CellClickAction is set to SelectRecord.
I was thinking of adding an attached behavior which would do some sort of hit testing and provide a current cell feature.
Thanks for the tip toreaurstad,
I did find this post very useful, I too was not experiencing the desired behavior until I set the CellClickAction to SelectRecord.
In our case, we are always using XamDataGrid in read-only mode - we want it to perform similarly to a ListBox. I therefore set the RecordSelectorLocation to None, hoping to use the rows themselves as the selection mechanism. This only worked however, once I set the CellClickAction to SelectRecord - with this property set to anything else, it's not possible to hold Ctrl or Shift and click (or press 'spacebar') on new rows to expand the selection.
I did notice however (not totally unexpectedly), that with the grid set as above, there is no ActiveCell being returned. I set the SelectionTypeCell property of the FieldLayoutSettings to Single - but was still unable to select cells. I've got a feeling I'll need some sort of hybrid of both modes, as we definately want the ListBox style control and navigation, but will also require the ability to have mouse-over cell styling and the ability to detect which cell is being right-clicked (for the purposes of enabling/disabling commands on a context menu).
I've not yet tried to achieve this additional functionality, but if anyone has, or has any ideas, they would be most appreciated.
Cheers,
Dave
I don't understand. My test last night showed multi-selection working as expected. I could select ranges with shift and/or multiple rows with control.
What is being deselected? I saw my selection being expanded. Only until you click on a cell without a modifer (shift/control) will the previous selection be deselected, which is how all windows apps work.
I also had to set the cellclickaction to selectrecord. This should have been the default behavior. When you click a new cell, all records
are by default deselected. Is it possible to programmatically trap this event from happening by setting e.Handled = true or similar? Here is the
XAML that does this simple selection that you see in Excel. Click a cell, the record is also selected. Shift or ctrl, easy as that. Hope somebody
out there finds my tip helpful, this really is the way XamDataGrid should select by default, but that is my opinion:
<local:XamDataGridCustom.FieldSettings>
<igDP:FieldSettings AllowEdit="False" CellClickAction="SelectRecord" />
</local:XamDataGridCustom.FieldSettings>
<local:XamDataGridCustom.FieldLayoutSettings>
<igDP:FieldLayoutSettings AutoGenerateFields="False" SelectionTypeRecord="Extended"
AutoArrangeCells="Default"/>
</local:XamDataGridCustom.FieldLayoutSettings>