Hello,
I have configured a datagrid, so that it looks and behaves more or less like Excel (for instance, by setting CellClickAction to CellSelect) I would like to implement the feature that user can press a mouse on the border of the cell and drag it to some other cell(s), and value will be copied in these cells on drop. Pretty much drag'n'drop as in Excel. I'm pretty much sure that "there is no intrinsic functionality to do this" :), but maybe there is still a way to implement this.
Probably a good starting point is SelectionDrag event in the DataGrid. But how can I determine that the border of the cell was clicked (and not somewhere in the middle of the cell)? The next question would be, can I provide some visual help about cells which will be affected by the drop operation (like Excel does)?
Thanks
There's no way to tell that the user clicked on a cell's border, really. The border itself is not a separate element, it's just drawn. But you don't really need to kinow that the clicked on a border, you just want to know that they clicked near the edge of the cell, right? That's where the border is.
So what you can do is use the UIElement structure of the grid and get a UIElement from the point that was clicked. There are lots of KB articles in the Infragistics Knowledge Base that describe how to do this. Like this one:
HOWTO:UltraWinGrid Mouse Position and Cell Identification
This article shows you how to get the cell, which you will probably need in this case, anyway. But what you can also do is use the cell UIElement to get the Rect of the cell and compare that with the mouse position to see if the user clicked somewhere on or near the edges of the cell.
Regarding the visual indicator on the cell, I think you will have to use a DrawFilter for that and draw it yourself.
Hello Mike,
Sorry for not answering for such a long time. I've tried different approaches and because of magnitude of problems with single features which constitute this "Excel-like behavior" I’ll stop the implementation and replan it later.
For instance, I wanted to make selected cell have a bold border (just like Excel does). After >2 weeks of everyday discussion with Infragistics support it was stated that the only way to do this is to use a DrawFilter. There is indeed a SelectedCellAppearance in the UltraGrid, but it is absolutely useless because the settings of SelectedCellAppearance will be overridden by default values of CellAppearance and RowAppearance.
According to Infragistics Support:
"The fundamental idea to understand with your issue is that the cell borders are not always drawn by the cell itself. Cells are drawn on the grid from left to right and top to bottom. Therefore when cell 1 is drawn and the cellspacing is zero, the next cell, "cell 2"s left border will overwrite cell 1's right border. Then after all of the cell's are drawn, the rows draw their borders which overwrite the cells' top and bottom borders. Now when the BorderColor is applied 'cell 1', that cell only controls one of its borders. Theoretically, it is possible to write a DrawFilter that merges the cell borders and row borders to behave the way that you intend when selecting cells. However, it would be very complex and would be totally dependent on any other styling, formatting, cell processing, and row processing that your particular grid handles. In fact, you may need multiple DrawFilters to handle different runtime scenarios to achieve the same appearance results. I believe what development was attempting to convey was that the grid's architecture is not designed to handle the SelectedCellAppearance in this way and any change would be an enormous effort of rearchitecting the WinGrid control itself. So much so, that it would be outside of the realm of a traditional 'Bug Fix' and development declined to do any code refactoring in our current releases for this issue. "
As far as I can judge, the whole concept of appearances (and decision which appearance should override another) is broken in the UltraGrid.
I expect that I will need to do much more ugly coding with DrawFilters (and similar things) than I’ve thought initially. Therefore I will cancel this feature for this release and replan it for the next one (if at all).
Thank you anyway for your help. It’s a pity that you’re not in Infragistics Support.
Developer support is correct. If every cel in the grid drew all four border sides, then either the borders would have to overlap (which would result in the same problem you are having now) or there would be double-thickn borders between each cell (which would be ugly). In fact, you can acheive this second result by setting the CellPadding property to 1. This introduces a space between cells and thus each cell has to draw all 4 border sides.
Andrej Kuklin said:As far as I can judge, the whole concept of appearances (and decision which appearance should override another) is broken in the UltraGrid.
I think that's a bit of an overstatement. Appearance in the grid work great for Fonts, BackColor, ForeColor, Text Alignment, Image Alignment, etc. They even work pretty well for borders if you apply settings on a higher level such as a band.
As far as cell borders go, I must agree with you. In this regard, the Appearance is pretty much useless.
But remember that the Appearance class is a sort've generic class that applies to many different objects across the entire set of Infragistics WinForms controls. So not every object is going to be able to support every appearance property. Appearances are very powerful, but there are, of course, always trade-offs.
I recommend that you Submit a feature request to Infragistics and suggest that a feature be added to the grid to allow cell borders in a more useful way. This is a very popular request, and I would not be surprised if it was implemented in a future release.
Already done (FR10682).Thanks again for you help
did you manage to implement Excel like cell value drag / drop? It wouold be nice if you could share some ideas - where to mind attention :-)
Thank you in advance.
Nope, we dropped this idea. Too difficult, too instable, lot's of implementation necessary which is based on not officially supported API (DrawFilter etc.), too little return in improved user experience
Thank you for your quick response. This is what I was afraid of :-)