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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

fast search

Thread ID:

Created:

Updated:

Platform:

Replies:

33804 Aug 26,2005 07:06 AM Aug 29,2005 10:09 AM Windows Forms 5
loading
Tags: GridControl
Catinat Velmourougan
Asked On August 26, 2005 07:06 AM

hi, 1. We want to do a find operation on teh grid. Are there any ways to make it faster? Its very slow now. We use filterdescriptor for this purpose. 2. I need to store a subset of GridGroupingControl.Table.Records to some collection and add , remove records from it. how to do it? regards, catinat

Administrator [Syncfusion]
Replied On August 26, 2005 02:11 PM

1) Can you access the data directly from your datasource. This may be faster. Here is a sample using a GridDataBoundGrid that just uses the datasource to do things faster that using teh grid directly. Here is one technique that implements a find from scratch. In this sample, a GridDataBoundGrid with 20000 rows can return all occurrences of a string in less than 100 msecs on my system. It does so by copying the column to an arraylist, and using ArrayList.IndexOf to do the searching. Now th this simple implementation, this requires a full word match. But you can use a ListBox and ListBox.FindString to do ''startswith'' searching. 2) You could use an ArrayList.

Catinat Velmourougan
Replied On August 29, 2005 07:49 AM

hi, Actually i should have been more clear on my questions.Sorry about that. 1.We are using gridgrouping control. The requirement is to do a search within 0.5 secs. We have a search, which is now takes 2 secs. I am attaching the search code which you can go through.If you can suggest some improvements, it will be better. This code takes 1 sec. After we find a record, we make a col of ther record active based on other cols value.Say I have colChoice, colChoice1, colChoice2, colChoice3. If the value of colChoice is 1 we make colChoice1 the active cell and call beginedit on it , if its 2 we make colChoice2 the active cell and if its 3 we make colChoice3 the active cell.This takes about 1 sec. When we ran a profiling tool to find out the most time consuming lines of code. we found that this.grid.endupdate(true) was the maximum time consuming. I am attaching the second process also. 2. When I said a collection actually I was looking for RecordCollection or like a list eg.ImageList.Is there anything like that?We will try with arraylist. >1) Can you access the data directly from your datasource. This may be faster. Here is a sample using a GridDataBoundGrid that just uses the datasource to do things faster that using teh grid directly. >Here is one technique that implements a find from scratch. In this sample, a GridDataBoundGrid with 20000 rows can return all occurrences of a string in less than 100 msecs on my system. It does so by copying the column to an arraylist, and using ArrayList.IndexOf to do the searching. Now th this simple implementation, this requires a full word match. But you can use a ListBox and ListBox.FindString to do ''startswith'' searching. > >2) You could use an ArrayList. Find_6007.zip

Administrator [Syncfusion]
Replied On August 29, 2005 08:28 AM

Instead of trying to lock the updating, creating and removing a filter, I think it will be faster just to loop through the records yourself. This way, you do not have to call Begin/EndUpdate and you can break the search as soon as you get a hit. You also do not have to create a filter and remove it. So, instead of grid.BeginUpdate(); ... RecordFilterDescriptor filter = new RecordFilterDescriptor("quickSearch"); filter.Expression = "[" + colName + "] LIKE ''" + text + "*''"; this.grid.TableDescriptor.RecordFilters.Add(filter); if (this.grid.Table.FilteredRecords.Count > 0) { rec = (GridRecord) this.grid.Table.FilteredRecords[0]; } this.grid.TableDescriptor.RecordFilters.Clear(); ... grid.EndUpdate(); You can try code like:
public GridRecord Find(string text)
{
	GridRecord rec = null;
	GridRecord oldRec = (GridRecord) this.grid.Table.CurrentRecord;
	try
	{
		string colName="";
		if (grid.TableDescriptor.GroupedColumns.Count > 0)
		{
			colName = this.grid.TableDescriptor.GroupedColumns[0].Name;
		} 
		else if (this.grid.TableDescriptor.SortedColumns.Count > 0)
		{	
			colName = this.grid.TableDescriptor.SortedColumns[0].Name;
		}
		else 
		{
			return rec;
		}
		foreach(GridRecord r in this.grid.Table.Records)
		{
			if(r.GetValue(colName).ToString().StartsWith(text))
			{
                                                       rec = r;
                                                       break;
                                          }
                            }
	}
	catch (Exception ex)
	{
		System.Console.WriteLine(ex.Message + " " + ex.StackTrace );
	} 
	if (rec!=null) {
		this.grid.Table.CurrentRecord = rec;
	} 
	else {
		if (oldRec != null ) {
			  this.grid.Table.CurrentRecord = oldRec;
		  }
	}
	return rec;
}
If this is still too slow, then go directly to the datasource and do not use grid.Table.Records to access the data.

Catinat Velmourougan
Replied On August 29, 2005 10:01 AM

hi, Can you look into the other process I have mentioned once we do a find.Because our 2 seconds includes this process also. regards, catinat

Administrator [Syncfusion]
Replied On August 29, 2005 10:09 AM

I would try removing the BeginUpdate and EndUpdate lines (provided you have used the other change (not using the grid to filter out the records) I suggested).

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

;