Quantcast
Channel: DevExpress Support Center (Examples)
Viewing all articles
Browse latest Browse all 7205

How to merge cells horizontally in GridView via the CustomDrawCell event

$
0
0

This example illustrates an approach that is similar to that one described in the following thread: How to merge cells horizontally in GridView.
The mentioned functionality is implemented via the GridView.CustomDrawCell event handling.

In addition, this example illustrates how to implement merged text scrolling.


Question Comments

Added By: VikV at: 5/23/2014 1:55:46 PM    

There is a problem with this code.  Unfortunately, the width of the merged cell is incorrectly calculated once you start resizing grid.  So, everything looks fine when you first show the grid, but as you make the grid *smaller*, eventually lines and text next to the merged cells are overwritten/hidden.  This is visible if you set the background of your merged cells to a color.

The reason for this is that the calculations of the "textRect" involve e.Bounds and column.Width, which do not seem to be correct as the grid is resizing.  Instead, you need to use the grid's GridViewInfo to get the GridCellInfo, which will then give you the proper bounds for the cell(s).  I used this method and got my grid to correctly resize.

So in essence, the problem is with GridColumn.Width not correctly being the cell's width when making the grid smaller.  For some reason, making the grid bigger (horizontally) does not have a bad effect, only making it smaller.

Added By: Andrew Ser (DevExpress Support) at: 5/26/2014 5:22:45 AM    

Hello,
Thank you for the cooperation. We will take your corrections into account and update this example soon.

Added By: Bijal Patel at: 7/29/2015 10:25:44 AM    

Using this code sample I am able to successfully merge cells horizontally. But how do I unmerge those cells if the value in those previously merged cells is now empty.

Added By: Alexey Z (DevExpress Support) at: 7/29/2015 1:25:10 PM    Hello,

As I see, you have already created a separate thread - Merging cells data from two or more adjacent columns on the same row.. Let's continue our discussion there.

Viewing all articles
Browse latest Browse all 7205

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>