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

Sort icon on column header question

Hi, To add a sort icon on the header of one column of a virtual grid where should I add those lines: Grid.CellModels.Add(''ColumnHeaderCell'', GridSortColumnHeaderCellModel.Create(Grid.Model)); e.Style.CellType := ''ColumnHeaderCell''; e.Style.Tag := ListSortDirection.Ascending; I tried to add those lines in the QueryCellInfo method for a partiular line and column ((e.RowIndex = 0) and (e.ColIndex = 2)) but I can see no sort icon on my grid. Moreover with this code added, when I click on the column headers I sometime get a big white square with a red cross in it replacing my grid... Another unrelated question: which is the exact meaning of the e.Handled line that should be added in the QueryCellInfo and SaveCellInfo methods ?? Thanks, Verane.

9 Replies

AD Administrator Syncfusion Team August 26, 2004 06:42 AM UTC

I am not sure what GridSortColumnHeaderCellModel.Create does, but I assume it returns an cached instance of a cellmodel. You should add the celltype only once, not every time you use it. So, try moving Grid.CellModels.Add(''''ColumnHeaderCell'''', GridSortColumnHeaderCellModel.Create(Grid.Model)); to FormLoad or somewhere it will be hit once before your grid is drawn the first time. At that point you can just use new to create an instance and not have a cached instance that you retrieve. (The grid will cache it for you.)


AD Administrator Syncfusion Team August 26, 2004 08:30 AM UTC

In fact it is what I tried to do originally, but when I put the ''Grid.CellModels.Add(''''ColumnHeaderCell'''', GridSortColumnHeaderCellModel.Create(Grid.Model));'' in the formLoad I get the following error when executing my project: ''unhandled exception class System.ArgumentException...'' Verane. >I am not sure what GridSortColumnHeaderCellModel.Create does, but I assume it returns an cached instance of a cellmodel. > >You should add the celltype only once, not every time you use it. So, try moving > >Grid.CellModels.Add(''''ColumnHeaderCell'''', GridSortColumnHeaderCellModel.Create(Grid.Model)); > >to FormLoad or somewhere it will be hit once before your grid is drawn the first time. At that point you can just use new to create an instance and not have a cached instance that you retrieve. (The grid will cache it for you.)


AD Administrator Syncfusion Team August 26, 2004 09:08 AM UTC

What is GridSortColumnHeaderCellModel.Create? Try using the same code that is in the grid\sample\GridControlSort sample. It works there. this.gridControl1.CellModels.Add("ColumnHeaderCell", new GridSortColumnHeaderCellModel(this.gridControl1.Model));


AD Administrator Syncfusion Team August 26, 2004 09:54 AM UTC

''GridSortColumnHeaderCellModel.Create'' is the equivalent of ''new...'' in Delphi. I cannot use ''new'', it is not a keyword in Delphi. Verane. >What is GridSortColumnHeaderCellModel.Create? > >Try using the same code that is in the grid\sample\GridControlSort sample. It works there. > >this.gridControl1.CellModels.Add("ColumnHeaderCell", new GridSortColumnHeaderCellModel(this.gridControl1.Model)); >


AD Administrator Syncfusion Team August 26, 2004 10:10 AM UTC

I am not familiar with .NET Delphi so I do not know where you need to place this creation code. But you should not be doing it in a place that will be hit repeatedly like QueryCellInfo. It should be placed after the grid has been created. In FormLoad, has the grid been created when you make this call? You might try calling grid.Initialize() before trying to add the model to see if that allows things to work. Can you get more infomation from the debugger, like a full call stack? That might point to what is not properly initialized when you try this call. Another thing you can try is to subscribe to the grid''s Paint event. In your Paint handler, inmmediately unsubscribe to the Paint event (so this handler is only executed once). Then try creating the cell model in the paint handler code. It is likely that everything is initialized before Paint is called for the first time.


AD Administrator Syncfusion Team August 26, 2004 11:00 AM UTC

When I add the model in the paint event, I get the same error message (I join the call stack). Does the sample code of the knowlegde base works with virtual grid ? May be there is a problem because I use Delphi ? (but I thought the grid had been tested with Delphi, I read that in one message of the forum). Verane. >I am not familiar with .NET Delphi so I do not know where you need to place this creation code. But you should not be doing it in a place that will be hit repeatedly like QueryCellInfo. > >It should be placed after the grid has been created. > >In FormLoad, has the grid been created when you make this call? You might try calling grid.Initialize() before trying to add the model to see if that allows things to work. > >Can you get more infomation from the debugger, like a full call stack? That might point to what is not properly initialized when you try this call. > >Another thing you can try is to subscribe to the grid''s Paint event. In your Paint handler, inmmediately unsubscribe to the Paint event (so this handler is only executed once). Then try creating the cell model in the paint handler code. It is likely that everything is initialized before Paint is called for the first time. pic1_2793.zip


AD Administrator Syncfusion Team August 26, 2004 11:58 AM UTC

I will try to provide you with a Delphi sample later today or tomorrow showing a virtual grid with a sort column header cell.


AD Administrator Syncfusion Team August 27, 2004 09:20 AM UTC

Yes I would be very interested in a sample code. Thanks by advance, Verane.


AD Administrator Syncfusion Team August 27, 2004 12:08 PM UTC

Here is a minimal sample. I did not seem to have a problem creating the cell type from within FormLoad. I see the sort header in column 3, and when I click it, it flips directions. Now it does not really sort anything since this is a virtual grid, and you would need to sort your external data source in some manner. In this sample, the row an dcolumn values are used to display data in the cell so this will not sort. Borland Studio Projects_1761.zip

Loader.
Live Chat Icon For mobile
Up arrow icon