We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Merging caption of two column captions

I have a grid with a number of columns, but I need to merge the captions for two columns into one string that spans both column headers. I''ve tried using CoveredRanges.Add() passing in GridRangeInfo.FromTlhw(0, requiredColIndex, 1, 2) Where requiredColIndex = grid.TableDescriptor.NameToField("AMOUNT1"); But it doesn''t work???

9 Replies

AD Administrator Syncfusion Team June 10, 2004 05:52 PM UTC

Hi Jason, you need to handle the QueryCoveredRange event as shown below: this.groupingGrid1.TableModel.QueryCoveredRange += new Syncfusion.Windows.Forms.Grid.GridQueryCoveredRangeEventHandler(TableModel_QueryCoveredRange); } private void TableModel_QueryCoveredRange(object sender, Syncfusion.Windows.Forms.Grid.GridQueryCoveredRangeEventArgs e) { GridTableModel tm = sender as GridTableModel; Element el = tm.Table.DisplayElements[e.RowIndex]; if (el is ColumnHeaderRow) { GridTableCellStyleInfo style = tm[e.RowIndex, e.ColIndex]; // You could use Column name here //if (style.TableCellIdentity.Column.Name == "CustomerID" // || style.TableCellIdentity.Column.Name == "CompanyName") // or - more simple - just use the underlying grids column index. if (e.ColIndex >= 3 && e.ColIndex <= 4) e.Range = GridRangeInfo.Cells(e.RowIndex, 3, e.RowIndex, 4); e.Handled = true; } } Stefan


AD Administrator Syncfusion Team June 11, 2004 07:45 AM UTC

Thanks for you reply, Stefan. That doesn''t do exactly what I needed. I have two numeric columns "Unadjusted" and "Adjusted", I''d like both of their caption cells to be merged into a single CoveredCell to display a string such as "Position" Could you provide further help?? Thanks Jason


AD Administrator Syncfusion Team June 11, 2004 02:40 PM UTC

The text that gets displaued in the covered cell will be the HeaderText of the firstt of the two columns. So, you could modify the HeaderText there. Another alternative would be to handle the QueryCellStyleInfo event. You could check row index and col index similar as is the QueryCoveredRange event and then assign e.Style.Text to change the text that gets displayed in the cell. Let me know if you need more details. Thanks, Stefan


AD Administrator Syncfusion Team June 14, 2004 08:01 AM UTC

Sorry to be a pain but I''m still not getting this to work. To clarify: I''m, using a GridGroupingControl with a single datatable. If I add a range to the CoveredCells should I exect that range to be merged into One cell without resorting to adding a handler for QueryCoveredRange: const string POSITION = "Position"; gridGroupingControl3.TableDescriptor.Columns[POSITION].HeaderText = "POSITIONS"; int positionColIndex = gridGroupingControl3.TableDescriptor.NameToField(POSITION); GridRangeInfo postHeadercols = GridRangeInfo.Cells(0, positionColIndex,0 , positionColIndex+1); gridGroupingControl3.TableModel.CoveredRanges.Add(postHeadercols); I can''t get the CoveredCells to work. I''ve attached a sapel app that contains various checkboxes to apply formatting - The MergeCaptions checkbox (checkbox7) is where I add to the coveredCells. Any help would be very much appreciated Thanks Jason gridgrouping03_8542.zip


AD Administrator Syncfusion Team June 14, 2004 10:11 AM UTC

FYI...I''ve changed my test app and noticed that using CoveredCells WITHOUT any grouping works fine, but as soon as I add any grouping the CoveredCells do not appear as Covered, but instead take the caption from another cell


AD Administrator Syncfusion Team June 16, 2004 12:30 AM UTC

Hi Jason, I assume that this is the same problem as in the other thread. So I''ll leave it here. But let me know if I got you wrong and this is a different sample. Thanks, Stefan


AD Administrator Syncfusion Team June 24, 2004 06:32 AM UTC

Thanks for your reply Stefan, but the other thrread doesn''t answer it exactly for me - although it''s probably in the right direction. I need the last two columns (POSITION and POSITIONADJ) to have their captions "covered" into a single cell that spans both, having a custom caption. This doesn''t seem to work when I''ve got some grouping applied. I assume I need to look for a specifiic type for Element (Element el = tm.Table.DisplayElements[e.RowIndex]) inside GridQueryCoveredRangeEventHandler and do somethhing accrordingly Can you help me some more??? Thanks


AD Administrator Syncfusion Team June 25, 2004 03:54 PM UTC

Jason, try the following code: if (el is ColumnHeaderRow) { GridTableCellStyleInfo style = tm[e.RowIndex, e.ColIndex]; if (style.TableCellIdentity.Column.Name == POSITION || style.TableCellIdentity.Column.Name == POSITIONADJ) { int startCol = el.GroupLevel+1; int colIndex = e.ColIndex; if (style.TableCellIdentity.Column.Name == POSITIONADJ) colIndex--; e.Range = GridRangeInfo.Cells(e.RowIndex, colIndex, e.RowIndex, colIndex + 1); e.Handled = true; } } I attached a modified form1.cs Form1_2269.zip Stefan


AD Administrator Syncfusion Team June 30, 2004 10:45 AM UTC

Hi Stefan, Yes!!! That''s exactly what I wanted!!!! Thank you very much Jason

Loader.
Up arrow icon