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. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Problem on soring grid?

Thread ID:

Created:

Updated:

Platform:

Replies:

17592 Aug 12,2004 03:53 PM UTC Aug 12,2004 11:57 PM UTC WinForms 7
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On August 12, 2004 03:53 PM UTC

Hi, I tried to combine sample of GridPerf and GridControlSort in my app. Therefore, I can get realtime data with sorting function on virtual grid. After that, whenever I sort, I always get exception as below, but nothing happens. Any suggestions? Thanks a lot Chris catched at Syncfusion.Windows.Forms.Grid.GridModel.SetCellInfo(Int32 rowIndex, Int32 colIndex, GridStyleInfo style, StyleModifyType modifyType, Boolean dontRaiseSaveCellInfoEvent, Boolean copyReferenceOnly) in :line 0 catched at Syncfusion.Windows.Forms.ScrollControl.RaiseCancelMouseEvent(MouseEventArgs e, CancelMouseDelegate d) in :line 0

Administrator [Syncfusion]
Replied On August 12, 2004 04:32 PM UTC

Actually, to further simplify my question: on syncfusion GridPerf sample, how to make sort work on VirtualGridControl? Thanks a lot Chris

Administrator [Syncfusion]
Replied On August 12, 2004 04:43 PM UTC

Are you sorting the DataSource independent of the grid? (Ie, for example if you external datasource is a DataView, are you sorting things by setting DataView.Sort?). If you sort indendent of the grid, make sure there is not a currently editing cell (by calling grid.CurrentCell.EndEdit) that may be causing a problem when you return from your sort. Below is a discussion of sorting a virtual grid using the grid itself (and not using the datasource to sort itself). One option to sort a vistual grid would be to create some sort of index array during your sort where the array tracks in some manner the relationship between the unsorted data and the sorted data. Then in your QueryCellInfo handler, you would use this array to get the proper reference for the requested row. Attached is a sample in C# that shows an implementation of this idea. Here are some details about the sample. It uses a two dimensional integer array called VirtData as the datasource for the grid. The datasource has an ArrayList (SortIndexList) with the capacity as the number of rows. It is initially populated with 0,1,2,3.. till the total rowcount. The virtdata class has an indexer that gets and sets the array values using the SortIndexList items. The grid is populated using the QueryCellInfo event handler using this indexer. Since the SortIndexList is populated like 0,1,2,3.. intially, it displays the array vlaues using this indexer. It uses the "ColumnHeaderCell" to display the up or down sort arrows when the column header cell is clicked to show the sort order. When the header cell is clicked, the SortIndexList''s sort method is called passing in the DataComparer which implements the IComparer interface. The IComparer re-arranges items (which we loaded intially like 0,1,2,3...) in a way to reflect either the ascending or descending way of array data in that particular column. So when the grid queries for information using the virtdata indexer, it gets the value in a sorted way and displays in the grid. Sample.

Administrator [Syncfusion]
Replied On August 12, 2004 04:48 PM UTC

Thanks Clay. Is that possible to use DataTable instead of ArrayList as GridPerf''s datasource? It is very convenient to have a DataTable since I can select a specific row I want and update/delete it. But I cannot find a way to sort table as ArrayList''s sort. T hanks Chris

Administrator [Syncfusion]
Replied On August 12, 2004 06:43 PM UTC

The grid\samples\databound\gridperf sample does use a DataTable as its datasource. To sort a DataTable, you can try setting dataTable.DefaultView.Sort property to teh column name you want to sort.

Administrator [Syncfusion]
Replied On August 12, 2004 08:10 PM UTC

Thanks Clay. Actually, I am trying to get sorting work on this sample first. Somehow, I could not get it work by setting DefaultView. I think I could make some dump mistakes somewhere. However, one thing in that sample which confuse me is this section in InitializeGrid method. Does it mean I CANNOT use defaultview to do the sorting at all if I follow as this sample? I have no clue where is that DataTableList class in this project. Thanks a lot Chris // DataView has performance issues when inserting new records into a large // dataset. Instead of getting the DataTable.DefaultView, the engine // can wrap the data table with a more efficient DataTableList class. // This allows instantenoues inserts for DataTable with > 100000 records. DateTime dtCount = DateTime.Now; this.grid.BeginUpdate(); this.gridPanel.Controls.Add(this.grid); this.grid.ResetVolatileData(); this.grid.Update(); >The grid\samples\databound\gridperf sample does use a DataTable as its datasource. > >To sort a DataTable, you can try setting dataTable.DefaultView.Sort property to teh column name you want to sort.

Administrator [Syncfusion]
Replied On August 12, 2004 09:33 PM UTC

To get that sample to sort when you click the header, 1) add this handler to the other handlers. this.grid.CellClick += new GridCellClickEventHandler(grid_CellClick); 2)Change the QueryCeinfo event. private void grid_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e) { if(e.ColIndex > 0 && e.RowIndex > 0) { //e.Style.CellValue = this.table.Rows[e.RowIndex-1][e.ColIndex-1]; e.Style.CellValue = this.table.DefaultView[e.RowIndex-1][e.ColIndex-1]; e.Handled = true; } } 3) Add this cell click handler.
private void grid_CellClick(object sender, GridCellClickEventArgs e)
{
	if(e.RowIndex == 0 && e.ColIndex > 0)
	{
		string s = this.table.DefaultView.Sort;
		string dir = "Desc";
		if(s.EndsWith(dir))
			dir = "";
		if(e.ColIndex == 1)
			s = "Name";
		else if(e.ColIndex == 2)
			s = "State";
		else if(e.ColIndex == 3)
			s = "Zip";
		if(dir != "")
			s = s + " " + dir;
		this.table.DefaultView.Sort = s;
		this.grid.Refresh();
	}
}

Administrator [Syncfusion]
Replied On August 12, 2004 11:57 PM UTC

Thank you very much for your quick response. I do appreciate it! Chris >To get that sample to sort when you click the header, >1) add this handler to the other handlers. > >this.grid.CellClick += new GridCellClickEventHandler(grid_CellClick); > >2)Change the QueryCeinfo event. > >private void grid_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e) >{ > if(e.ColIndex > 0 && e.RowIndex > 0) > { > //e.Style.CellValue = this.table.Rows[e.RowIndex-1][e.ColIndex-1]; > e.Style.CellValue = this.table.DefaultView[e.RowIndex-1][e.ColIndex-1]; > e.Handled = true; > } >} > >3) Add this cell click handler. >
>private void grid_CellClick(object sender, GridCellClickEventArgs e)
>{
>	if(e.RowIndex == 0 && e.ColIndex > 0)
>	{
>		string s = this.table.DefaultView.Sort;
>		string dir = "Desc";
>		if(s.EndsWith(dir))
>			dir = "";
>		if(e.ColIndex == 1)
>			s = "Name";
>		else if(e.ColIndex == 2)
>			s = "State";
>		else if(e.ColIndex == 3)
>			s = "Zip";
>		if(dir != "")
>			s = s + " " + dir;
>		this.table.DefaultView.Sort = s;
>		this.grid.Refresh();
>	}
>}
>

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;