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

event handling issues

hi, In our application, the grid takes up a long time to come up.We are trying to optimise the performance.We are using a grid grouping control. Can you give us some insight as how to improve the performance? One of the points we felt was there are two many events coming up for each and every cell. For example, in our prepare view style info event we have the following code snippet : GridTableCellStyleInfo style = e.TableControl.Model[e.Inner.RowIndex, e.Inner.ColIndex]; if(style.TableCellIdentity.TableCellType != GridTableCellType.RecordFieldCell && style.TableCellIdentity.TableCellType != GridTableCellType.AlternateRecordFieldCell || (style.TableCellIdentity.DisplayElement.ParentRecord == e.TableControl.Table.CurrentRecord)) { e.Inner.Style.Borders.Bottom = new GridBorder(GridBorderStyle.Solid, Color.Black); e.Inner.Style.Borders.Top = new GridBorder(GridBorderStyle.Solid, Color.Black); } This code snippet goes and calls Querycellstyleinfo and once again the querycellstyleinfo gets called.The seq of events are as follows: 1.Prepareviewstyleinfo 2.Querycellstyleinfo and again 3.Querycellstyleinfo. How to prevent the querycellstyleinfo being called again?

11 Replies

AD Administrator Syncfusion Team August 10, 2005 01:20 PM UTC

Using the indexer is what is triggerring QueryCellStyleInfo. Instead, just try using tHE style that was passed into the event. GridTableCellStyleInfo style = e.Inner.Style as GridTableCellStyleInfo;

CV Catinat Velmourougan August 10, 2005 01:42 PM UTC

hi, Great! Even we were looking at the same but we missed on the part of casting it to GridTableCellStyleInfo. ok now the next problem we are working on is the number of times the querycellstyleinfo is getting called.We have only 3 x 7 grid so 21 cells including the columnheaders(no rowheaders included) so ideally the querycellstyleinfo should get called only 21 times but its getting called a whooping 91 times. Have any idea on it? regards, catinat

AD Administrator Syncfusion Team August 10, 2005 01:50 PM UTC

Where is your mouse as you do this counting? QueryCellInfo is hit as you move the mouse over the cells. Additionally, for each cell, QueryCellInfo is called to get the tablestyle (rowindex = -1, colindex = -1), rowstyles (row>0, col = -1), colstyles(row=-1, col > 0) and finally the cell style. So, it is call many times. This is why most QueryCellInfo code blocks start out like if(e.ColIndex > 0 && e.RowIndex > 0).

CV Catinat Velmourougan August 10, 2005 02:04 PM UTC

hi, This is just when the application comes up for the first time.We think its pretty much ok.WE actually put the following line in querycellstyleinfo : Console.WriteLine("Column amNe :" + e.TableCellIdentity.Info); The cell info printed shows it picks up so many variety of cells as you said.It seems theres no repetition here.So we are trying to look into other events.We want to reduce events as much as possible.Are there any performance optimisation samples,documents that we can look into? thanx, catinat

AD Administrator Syncfusion Team August 10, 2005 02:26 PM UTC

What work are you doing in QueryCellStyleInfo? Why are you subscribing to the event?

CV Catinat Velmourougan August 11, 2005 04:15 AM UTC

hi, We are doing the following tasks: 1. We change the color of text based on its value.For example, if its less than zero we make it red. 2.We change the image displayed on the column, based on the value of related cols.For example, if col1 == val1 and col2 == val2 we make col3 == image3. 3.We have nested tables.So in case there are child rows we show +. regards, catinat

AD Administrator Syncfusion Team August 11, 2005 08:14 AM UTC

QUeryCellStyleInfo will be hit a lot. There is no way around this. So, to minimize this effect, you should work to eliminate code that triggers QueryCellStyleInfo if possible (as in your PrepareViewStyleInfo code). You should also make sure teh QueryCellStyleInfo code is as efficient as possible. If there are time consuming operations in your QueryCellStyleInfo code, you should try to reduce this load by maybe caching values or something that turns a time consuming operation into a simple hashtable lookup or something. The things you listed above are pretty straight forward things to do in QueryCellStyleInfo. (You could move 1 to PrepareViewStyleInfo, but I do not think that will buy you anything). As long as you judiciously use If-statements to avoid the hitting code when you do not need it, I am not sure you will be able to improve things. If you comment out your QueryCellStyleInfo handler, do you see any significant gain in the performance?

CV Catinat Velmourougan August 11, 2005 08:41 AM UTC

hi, We didnt see any significant improvement after removing the querycellstyleinfo.We have moved out code as much as possible and we did our best to make the code as efficient as possbile by using if as you have said.We have removed our prepare viewstyleinfo method and after that we can see good improvement.But still the scrolling, is slow.Our grid is also heavy with say the worst case scenario we have 3000 x 200 columns. But even for a grid with 5 x 3000 we see the scrolling is slow.I think querycellstyleinfo is the only event which is getting called while scrolling.ANy best practices to improve scrolling?

AD Administrator Syncfusion Team August 11, 2005 09:45 AM UTC

If removing your PrepareViewStyleInfo code gives you better perfomance, can you psot you method to see if we can make suggestions on it. In teh code you showed above, you might cretae a form member, blackBorder and create it once. Then In prepareviewStyleInfo, you could just set this member instead of creating new every time. Not sure this will help, but it is the kind of thing you can try. I will also ask the grid architect is he has any suggestions for improving scrolling. You should be using our latest code as it has improvements over the 2.x and 3.0 code.

CV Catinat Velmourougan August 11, 2005 12:56 PM UTC

hi, This is what I we have in querycellstyleinfo if(e.TableCellIdentity.TableCellType == GridTableCellType.AlternateRecordFieldCell || e.TableCellIdentity.TableCellType == GridTableCellType.RecordFieldCell) { if(e.TableCellIdentity.Column != null) { if (e.TableCellIdentity.Column.MappingName == c1 || e.TableCellIdentity.Column.MappingName == c2 || e.TableCellIdentity.Column.MappingName == c3) { string mappingName = e.TableCellIdentity.Column.MappingName; GridRecord rec = e.TableCellIdentity.DisplayElement.ParentRecord as GridRecord; if(rec != null) { object o = rec.GetValue(mappingName); double d; if(double.TryParse(o.ToString(), System.Globalization.NumberStyles.Any, null, out d)) { if(d < 0) { e.Style.TextColor = Color.Red; } } } } if(e.TableCellIdentity.Column.Name == "Img1") { GridRecord rec = e.TableCellIdentity.DisplayElement.ParentRecord as GridRecord; if(rec != null) { object assetId = rec.GetValue("c1"); string newIssueFlag = Convert.ToString(rec.GetValue("c2")); double outAssetId; if(double.TryParse(assetId.ToString(), System.Globalization.NumberStyles.Any, null, out outAssetId)) { if(outAssetId > 0 && newIssueFlag == "c3") { e.Style.CellValue = imageList1.Images[0]; } else if(outAssetId < 0 && newIssueFlag == "c4") { e.Style.CellValue = imageList1.Images[2]; } else { //e.Style.CellValue = SystemIcons.Error.ToBitmap(); } } } } if(e.TableCellIdentity.Column.Name == "Img2") { GridRecord rec = e.TableCellIdentity.DisplayElement.ParentRecord as GridRecord; if(rec != null) { object modifiedTimeStamp = rec.GetValue("c1"); if(modifiedTimeStamp != System.DBNull.Value) { //o = Convert.ToDateTime(rec.GetValue("c2")); DateTime dt; dt = DateTime.Parse(modifiedTimeStamp.ToString()); if(dt.Date == DateTime.Now.Date){ e.Style.CellValue = imageList1.Images[1]; } } } } } } if (e.TableCellIdentity.TableCellType == GridTableCellType.RecordPlusMinusCell) { Record r = e.TableCellIdentity.DisplayElement.ParentRecord as Record; //&& r.ParentTable.TableDescriptor.Name != DataSetBuilder.SALESTRANSACTION_LIST if (r != null && r.NestedTables.Count > 0 && r.NestedTables[0].ChildTable.GetFilteredRecordCount() == 0) { e.Style.CellType = "Static"; } } }

AD Administrator Syncfusion Team August 11, 2005 03:44 PM UTC

There are a couple of simples things that you can do to your code to probably make it more, but I am not sure the changes will affect things that much. You can use ''else if'' in two of the mutually exclusive checks your doing the aviod one comparison each time through. For example if the Name is "Img1", there is no reason to check if it is "Img2". Simialry, if it is a recordfield celltype, then you do not have to check if it is a plusminus. I suspect the time consuming part of this code is the two calls to double.TryParse. You could sort of hard code these values (instead of using TryPasre) to test whether this is in fact the case. If it is, then there is something you can do. You can actually derive the GridRecord class and add your own properties. You could have a property for each of the doubles you need. The idea would be to only do a TryParse if the values have changed, and otherwise just use the previously parsed value cached in your new record properties. The trick is how do you know when a value is changed. There is a Table.EngineVersion property that is increameted any time the table is changed. So, you could add a Version property to the record that tracks this EngineVersion that existed when the value was last parsed. Then in QueryCellStyleInfo, you can check the Table.EngineVersion against the record.Version value, and if they do not match, call TryParse updating the record.Version and the cache dowble value. This way TryParse woul dnot be used unless there was a possibility that something changed that might affect your test values.

Live Chat Icon For mobile
Up arrow icon