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

Adding a push button to the "Summary" Header

Hello, Is there any way in which I can add a "push button" to the right hand side of the summary headers on a grouping grid. I want to be able to use this button to select all checkboxes in a certain column, for that particular group. I can change the whole header into a large button, by the following code:- private void TableControl_PrepareViewStyleInfo(object sender, GridPrepareViewStyleInfoEventArgs e) { if(e.Style.CellType == "Header") { string formtext = e.Style.FormattedText.ToString(); e.Style.CellType = "PushButton"; e.Style.Description = formtext; } This makes the header into a large button with the description. But I would like a small button placed on the right hand side of the summary in the header row. Thanks, David.

6 Replies

Administrator September 21, 2004 12:26 AM UTC

David, You could handle TableModel.QueryCoveredRange. The GridTable class internally handles QueryCoveredRange and executes the code below for DisplayElementKind.Caption: protected virtual void OnQueryCoveredRange(GridQueryCoveredRangeEventArgs e) { GridTable thisTable = this; if (e.RowIndex < thisTable.DisplayElements.Count) { Element el = thisTable.DisplayElements[e.RowIndex]; switch (el.Kind) { case DisplayElementKind.Caption: { int maxCaptionColCount = Math.Max(this.GetColumnIndentCount(), TableDescriptor.GetColCount()-1); int startCol = el.GroupLevel+1; IGridGroupOptionsSource g = el.ParentGroup as IGridGroupOptionsSource; if (g != null && !g.GroupOptions.ShowCaptionPlusMinus) { startCol--; } int d = (RelatedTables.Count > 0) ? 1 : 0; if (!((GridTable) el.ParentTable).TableOptions.ShowRecordPlusMinus) d = 0; if (e.ColIndex >= startCol && e.ColIndex <= maxCaptionColCount) { if (g == null || !g.GroupOptions.ShowCaptionSummaryCells) { e.Range = GridRangeInfo.Cells(e.RowIndex, startCol, e.RowIndex, maxCaptionColCount); e.Handled = true; } else { e.Range = GridRangeInfo.Cell(e.RowIndex, e.ColIndex); if (e.Range.Left <= GetColumnIndentCount()) { e.Range = e.Range.UnionRange(GridRangeInfo.Cells(e.Range.Top, el.GroupLevel+1+d, e.Range.Bottom, GetColumnIndentCount())); e.Handled = true; } } } else if (e.ColIndex == el.GroupLevel) { e.Range = GridRangeInfo.Cell(e.RowIndex, e.ColIndex); e.Handled = true; // PlusMinus } else if (e.ColIndex > maxCaptionColCount) { e.Range = GridRangeInfo.Cell(e.RowIndex, e.ColIndex); e.Handled = true; } break; } } ] } So, what you could do is provide your own handler for QueryCoveredRange - copy paste above code into your handler and modify it to your needs. make sure to set e.Handled = true. This will instruct the grid not to exececute it''s own (above) covering mechanism for the DisplayElementKind.Caption Stefan

Administrator September 21, 2004 12:37 AM UTC

Or maybe better would be to create your own cell type, derive it from GridHeaderCellRenderer/GridHeaderCellModel and register it with groupingControl.TableModel, e.g. as "MyCaption" cell type. Then you can assign that celltype to groupingControl.Appearance.GroupCaptionCell.CellType = "MyCaption". In your derived cell type you can add a button (as shown in the Grid\Samples\In Depth\CellButtons example) or simply override OnDraw and do your own custom drawing for the caption cell. Stefan

DL David Llewellyn September 22, 2004 01:56 AM UTC

Hello Stefan. Thank you for your help. I have created a new gridcellbutton as you have suggested and it now looks good. Although, now I need to know what groupsummary header button has been clicked on. I am using a objectgrid_TableControlCellButtonClicked event, but how do I retrieve the summary data? For example, if the summary header is: Collection ID : Cars - 21 Items How do I interrogate this and retrieve this data? I need to be able to find the string "Cars".

DL David Llewellyn September 22, 2004 04:36 AM UTC

Hello Stefan, Please ignore the last message that I posted. I realise that I could use this code on the event click to obtain the summary caption string:- Element el = this.objectgrid.Table.DisplayElements[e.Inner.RowIndex]; string captionsummary = el.Info.ToString(); Thanks for your help. David

Administrator September 22, 2004 08:36 AM UTC

David, don''t rely on the Info property - this is more for help with debugging to find out what kind of object you are dealing with ... Better do this: Group g = this.objectgrid.Table.DisplayElements[e.Inner.RowIndex].ParentGroup; string captionsummary = g.Category; // or CategoriesToString(); or GridTableCellStyleInfo style = this.objectgrid.TableModel[e.Inner.RowIndex, e.Inner.ColIndex]; Group g = style.TableCellIdentity.DisplayElement.ParentGroup; ... Stefan

DL David Llewellyn September 22, 2004 08:39 PM UTC

Hello Stefan, That works well. Thanks for your help. David.
Loader.
Live Chat Icon For mobile
Up arrow icon