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

RowIndex

I was trying to find the row index of the grid as the user either uses page down/up, arrow or mouse to select a row. I know there is RowIndex and MoveToRowIndex properties but they are not reliable as sometimes it retures "Invalid state: IsInMoveTo returns false" Is there a way that I can find the index of row inside a grid. Thanks

6 Replies

AD Administrator Syncfusion Team October 5, 2005 12:45 AM UTC

Here is some code. GridCurrentCell cc = this.gridGroupingControl1.TableControl.GetNestedCurrentCell(); Console.WriteLine(cc.RowIndex); But I am not sure it will give you what you want. In a GridGroupingControl, the rowindex is not all that helpful because there is no simple mapping between the grid rowindex and the data due to things like caption rows. summary rows, nested tables among many of things that complicate the mapping of the rowindex in the grid to something you might want to use. Exactly what are you trying to accomplish with the rowindex in the grid? If you are using a simple flat datasource with no grouping, etc., then the above code might serve your needs. But if not, then if you will explain what you are trying to do, maybe we can suggest some way to do it.


KE Ken October 6, 2005 05:43 PM UTC

Thanks for your reply and suggestions. I am trying to implement page down capability. Since we might have over ten thousand rows returning from database, we want to improve the performance of filling and loading by limiting the number of rows to 100 when user first loads the grid. I was using Fill("Table Name", start, MaxRow, DataSet). The first time I set the start to Zero and MaxRow to 100. As user either uses page down key or arrow key to scroll down until user hits the second last or last row of the grid, an event fired and called the Fill with startRow = 101 and MaxRow = 100. startRow would be 201 for next time, so forth and so on. I need to index of a row to find when the event and fill method fired. I was looking at at RowIndex and MoveToRowIndex, they are not reliable as I used page down key to scroll down. I sometimes got invalid state error. I cannot use CurrentRecord.GetSourceIndex either because the CurrentRecord.GetSourceIndex got mess up after sorting on columns. For now I indirectly got the rowindex by int pos = MyGrid.Table.DisplayElements.IndexOf( MyGrid.Grid.Table.CurrentRecord So far it works fine with arrow keys and pagedown/up keys. Just wonder do you have any other suggestions? Thankyou very much. >Here is some code. > >GridCurrentCell cc = this.gridGroupingControl1.TableControl.GetNestedCurrentCell(); >Console.WriteLine(cc.RowIndex); > >But I am not sure it will give you what you want. > >In a GridGroupingControl, the rowindex is not all that helpful because there is no simple mapping between the grid rowindex and the data due to things like caption rows. summary rows, nested tables among many of things that complicate the mapping of the rowindex in the grid to something you might want to use. > >Exactly what are you trying to accomplish with the rowindex in the grid? If you are using a simple flat datasource with no grouping, etc., then the above code might serve your needs. But if not, then if you will explain what you are trying to do, maybe we can suggest some way to do it.


AD Administrator Syncfusion Team October 7, 2005 02:20 AM UTC

Hi Ken, It does not look like you use any of the grid engines grouping features. So, first thing I suggest is that you use VirtualMode optimization and that you change the summaries are calculated. See this post: http://www.syncfusion.com/support/forums/message.aspx?MessageID=34232 For the paging, I would handle the QueryRowHeight method. That is called while the user scrolls through the grid and if it queries for certain record you can load more records at that time. I haven''t tried this ever so it could be you run into issues. See also the sample in http://www.syncfusion.com/support/forums/message.aspx?MessageID=35322 (this is for GridDataBoundGrid, for a GridGroupingControl you need to listen to groupingGrid.TableModel.QueryRowHeight) Stefan >Thanks for your reply and suggestions. > >I am trying to implement page down capability. Since we might have over >ten thousand rows returning from database, we want to improve the >performance of filling and loading by limiting the number of rows to 100 when user first loads the grid. >I was using Fill("Table Name", start, MaxRow, DataSet). The first time I set the start to Zero and >MaxRow to 100. As user either >uses page down key or arrow >key to scroll down until user hits the second last or last row of the grid, >an event fired and called >the Fill with startRow = 101 >and MaxRow = 100. startRow would be 201 for next time, so forth and so on. > >I need to index of a row to find >when the event and fill method fired. I was looking at >at RowIndex and MoveToRowIndex, >they are not reliable as I used >page down key to scroll down. I sometimes >got invalid state error. I cannot >use CurrentRecord.GetSourceIndex either because the CurrentRecord.GetSourceIndex got mess up after sorting on columns. > >For now I indirectly got the rowindex by >int pos = MyGrid.Table.DisplayElements.IndexOf( > MyGrid.Grid.Table.CurrentRecord > >So far it works fine with arrow keys >and pagedown/up keys. > >Just wonder do you have any other suggestions? > >Thankyou very much. > > >>Here is some code. >> >>GridCurrentCell cc = this.gridGroupingControl1.TableControl.GetNestedCurrentCell(); >>Console.WriteLine(cc.RowIndex); >> >>But I am not sure it will give you what you want. >> >>In a GridGroupingControl, the rowindex is not all that helpful because there is no simple mapping between the grid rowindex and the data due to things like caption rows. summary rows, nested tables among many of things that complicate the mapping of the rowindex in the grid to something you might want to use. >> >>Exactly what are you trying to accomplish with the rowindex in the grid? If you are using a simple flat datasource with no grouping, etc., then the above code might serve your needs. But if not, then if you will explain what you are trying to do, maybe we can suggest some way to do it.


AD Administrator Syncfusion Team October 7, 2005 02:27 AM UTC

Ken, I forgot: The mapping between row index and display element works as follows: // the display element at row rowIndex; Element el = groupingGrid.Table.NestedDisplayElements(rowIndex); // the record the element belongs to Record r = Element.GetRecord(el); // the record index in sorted records collection int sortedIndex = r.ParentTable.FilteredRecords.IndexOf(r); // or the record index in underlying datasource int unsortedIndex = r.ParentTable.UnsortedRecords.IndexOf(r); Now the other way round: you have a record and want to know the row index. int rowIndexOfRecord = groupingGrid.Table.NestedDisplayElements.IndexOf(record); All IndexOf operations are fast (we are not looping through elements here since the engine is all binary trees.) Stefan


KE Ken October 7, 2005 09:45 PM UTC

Well, I just tried out your suggestion. First there is no this.gridGroupingControl1.UseListChangedEvent in gridGroupingControl. Then everything is the same. Now I got QueryRowHeightEvent got fired three to four times as my mouse just move from one row to another. Then the my grid keep reflashing (resize got called many times). Does have something to do with UseListChangedEvent? >Hi Ken, > >It does not look like you use any of the grid engines grouping features. So, first thing I suggest is that you use VirtualMode optimization and that you change the summaries are calculated. > >See this post: > >http://www.syncfusion.com/support/forums/message.aspx?MessageID=34232 > >For the paging, I would handle the QueryRowHeight method. That is called while the user scrolls through the grid and if it queries for certain record you can load more records at that time. I haven''t tried this ever so it could be you run into issues. > >See also the sample in http://www.syncfusion.com/support/forums/message.aspx?MessageID=35322 (this is for GridDataBoundGrid, for a GridGroupingControl you need to listen to groupingGrid.TableModel.QueryRowHeight) > >Stefan > >>Thanks for your reply and suggestions. >> >>I am trying to implement page down capability. Since we might have over >>ten thousand rows returning from database, we want to improve the >>performance of filling and loading by limiting the number of rows to 100 when user first loads the grid. >>I was using Fill("Table Name", start, MaxRow, DataSet). The first time I set the start to Zero and >>MaxRow to 100. As user either >>uses page down key or arrow >>key to scroll down until user hits the second last or last row of the grid, >>an event fired and called >>the Fill with startRow = 101 >>and MaxRow = 100. startRow would be 201 for next time, so forth and so on. >> >>I need to index of a row to find >>when the event and fill method fired. I was looking at >>at RowIndex and MoveToRowIndex, >>they are not reliable as I used >>page down key to scroll down. I sometimes >>got invalid state error. I cannot >>use CurrentRecord.GetSourceIndex either because the CurrentRecord.GetSourceIndex got mess up after sorting on columns. >> >>For now I indirectly got the rowindex by >>int pos = MyGrid.Table.DisplayElements.IndexOf( >> MyGrid.Grid.Table.CurrentRecord >> >>So far it works fine with arrow keys >>and pagedown/up keys. >> >>Just wonder do you have any other suggestions? >> >>Thankyou very much. >> >> >>>Here is some code. >>> >>>GridCurrentCell cc = this.gridGroupingControl1.TableControl.GetNestedCurrentCell(); >>>Console.WriteLine(cc.RowIndex); >>> >>>But I am not sure it will give you what you want. >>> >>>In a GridGroupingControl, the rowindex is not all that helpful because there is no simple mapping between the grid rowindex and the data due to things like caption rows. summary rows, nested tables among many of things that complicate the mapping of the rowindex in the grid to something you might want to use. >>> >>>Exactly what are you trying to accomplish with the rowindex in the grid? If you are using a simple flat datasource with no grouping, etc., then the above code might serve your needs. But if not, then if you will explain what you are trying to do, maybe we can suggest some way to do it.


AD Administrator Syncfusion Team October 10, 2005 01:24 AM UTC

No the UseListChangedEvent has nothing to do with that. What you should do is cache a high water mark of the rowindex being passed to QueryRowHeight. Only if the rowindex is greater than your current high water mark you should take action. Stefan > >Well, I just tried out your suggestion. >First there is no this.gridGroupingControl1.UseListChangedEvent >in gridGroupingControl. >Then everything is the same. > >Now I got QueryRowHeightEvent got fired >three to four times as my mouse just move >from one row to another. Then the >my grid keep reflashing (resize got called >many times). Does have something to do >with UseListChangedEvent? > > > >>Hi Ken, >> >>It does not look like you use any of the grid engines grouping features. So, first thing I suggest is that you use VirtualMode optimization and that you change the summaries are calculated. >> >>See this post: >> >>http://www.syncfusion.com/support/forums/message.aspx?MessageID=34232 >> >>For the paging, I would handle the QueryRowHeight method. That is called while the user scrolls through the grid and if it queries for certain record you can load more records at that time. I haven''t tried this ever so it could be you run into issues. >> >>See also the sample in http://www.syncfusion.com/support/forums/message.aspx?MessageID=35322 (this is for GridDataBoundGrid, for a GridGroupingControl you need to listen to groupingGrid.TableModel.QueryRowHeight) >> >>Stefan >> >>>Thanks for your reply and suggestions. >>> >>>I am trying to implement page down capability. Since we might have over >>>ten thousand rows returning from database, we want to improve the >>>performance of filling and loading by limiting the number of rows to 100 when user first loads the grid. >>>I was using Fill("Table Name", start, MaxRow, DataSet). The first time I set the start to Zero and >>>MaxRow to 100. As user either >>>uses page down key or arrow >>>key to scroll down until user hits the second last or last row of the grid, >>>an event fired and called >>>the Fill with startRow = 101 >>>and MaxRow = 100. startRow would be 201 for next time, so forth and so on. >>> >>>I need to index of a row to find >>>when the event and fill method fired. I was looking at >>>at RowIndex and MoveToRowIndex, >>>they are not reliable as I used >>>page down key to scroll down. I sometimes >>>got invalid state error. I cannot >>>use CurrentRecord.GetSourceIndex either because the CurrentRecord.GetSourceIndex got mess up after sorting on columns. >>> >>>For now I indirectly got the rowindex by >>>int pos = MyGrid.Table.DisplayElements.IndexOf( >>> MyGrid.Grid.Table.CurrentRecord >>> >>>So far it works fine with arrow keys >>>and pagedown/up keys. >>> >>>Just wonder do you have any other suggestions? >>> >>>Thankyou very much. >>> >>> >>>>Here is some code. >>>> >>>>GridCurrentCell cc = this.gridGroupingControl1.TableControl.GetNestedCurrentCell(); >>>>Console.WriteLine(cc.RowIndex); >>>> >>>>But I am not sure it will give you what you want. >>>> >>>>In a GridGroupingControl, the rowindex is not all that helpful because there is no simple mapping between the grid rowindex and the data due to things like caption rows. summary rows, nested tables among many of things that complicate the mapping of the rowindex in the grid to something you might want to use. >>>> >>>>Exactly what are you trying to accomplish with the rowindex in the grid? If you are using a simple flat datasource with no grouping, etc., then the above code might serve your needs. But if not, then if you will explain what you are trying to do, maybe we can suggest some way to do it.

Loader.
Live Chat Icon For mobile
Up arrow icon