Is it possible you guys can post some sample code, that shows drag and drop from XamDataGrid's Field Chooser to the ColumnsFieldDropAreaControl. We have a XamDataGrid and XamPivotGrid in the same screen, and I want to be able to drag columns from XamDataGrid's field chooser to the ColumnsFieldDropAreaControl/RowFieldsDropAreaControl.
Hi Anand,
This might be tricky since the field chooser on the XamDataGrid and the ColumnsFieldDropAreaControl in the pivot grid have their own drag drop handling. I'm putting together a sample to see what can be done. I will get back to you after the investigation.
This was a bit simpler than I initially thought. As I said previously, the XamDataGrid implements it's own version of drag/drop and currently it is not possible to hook into this. So to make this work I handled the PreviewMouseLeftButtonDown event on the LabelPresenter inside the FieldChooser and the PreviewMouseLeftButtonUp event on the ToolWindow that contains the FieldChooser. When the button down event fires, I grab the Field and store it. In the button up event, as long as there's a valid Field I check to see if the mouse was released above the ColumnsFieldDropAreaControl. If it was released above this, it adds the appropriate dimension to the XamPivotGrid.DataSource.Columns collection.
I have attached my sample for your consideration. Let me know if you have any questions on this.
If you can please post some sample code for this. Thanks again Rob.
I tried putting a DragSource handler in the overriden Label Presenter style, this does the job for the Grid and the field chooser, but breaks the grouping functionality which we very much need. Any other clues would be greatly appreciated.
You probably overrode the default drag/drop functionality which means groupby won't work along with any of the other drag features the grid has. It's possible to setup my code to work with the normal LabelPresenters in the XamDataGrid but there is a slight issue where dragging the label outside of the grid and dropping it causes the Field to become hidden. The cursor also changes to an 'X' to indicate this. I haven't found a way to disable the cursor change but you can keep the Field from being hidden by handling the FieldPositionChanging event and canceling that. Take a look at my new sample. I basically just reused the code from the previous sample.
Hey Rob,
Thanks for your great work putting up this sample. This works partially. But like you say the 'X' sign is there, and also the dragging out column functionality breaks. Anywhere to get rid of this X sign, in the pivot area. It doesn't look droppable then. Or is this not achievable given the current internal drag and drop datagrid framework?
Cheers,
Anand
It's possible to modify this but it is done in a pseudo-hacky way. Yes, because of the internal drag/drop stuff disabling this is going to be impossible unless you are ok with modifying the source code directly and then making your own builds. What I ended up doing was letting the XamDataGrid do it's thing and then afterwards I would override the mouse cursor with my own cursor when necessary.
I tried overriding the mouse cursor every time the mouse moved but this produced noticeable flashing as the mouse bounced between the cursor the XamDataGrid applied and the cursor that I was applying. So I opted to let the XamDataGrid keep it's cursor the majority of the time until the mouse was directly over the ColumnsFieldDropAreaControl. Once the mouse appeared over this control I switched the cursor to something else. The idea here is to let the user know that he can drop the column there. Hopefully this is acceptable for you.
Hey Rob thanks for all this, one last question, is it possible to disable this 'X' completely when the pivot grid is visible (and not have this remove columns feature), but still have the drag and drop work to the Column Fields. and enable it back on later, when the pivot grid is not visible.
Sorry for the delay. You can disable the specific feature of removing columns by setting the XamDataGrid.FieldSettings.AllowHiding property to "Never".
Thanks Rob for putting this all together, this was very helpful.
You are very welcome. Glad to help out.