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
close icon

How to jump to a specifc record

Hi What''s the best way to get the grouping grid to jump to a specific record if I know the primary key for that record? On a related point, can I cache grid.Table.CurrentRecord into a variable, refresh the grid and then set grid.Table.CurrentRecord to my cached variable? Does it work by looking for a reference or does it extract the primary key in order to set the correct record? Thanks Jason

9 Replies

AD Administrator Syncfusion Team July 6, 2004 03:56 PM UTC

Jason, There a couple of ways to do this: The first way is to get the index of the record in the underlying datatable. DataView.Find will return that record index. You can use that record index to the get the Syncfusion.Grid.Record object that is associated with that record and then make that the current record: int dvIndex = dataView.Find(...); Record r = grid.Table.UnsortedRecords[dvIndex]; grid.Table.CurrentRecord = r; Another option is if the grid is sorted by that primary key field. Then you can drill down to the group that the record belongs to and in that group then call Records.FindRecord. This works also with non-primary key fields. The grid only needs to be sorted by that field. // Grouped by Country GridGroup germanyGroup = (GridGroup) this.groupingGrid1.Table.TopLevelGroup.Groups["Germany"]; Record r = germanyGroup.Records.FindRecord("Aachen"); - or - // Not grouped: Record r = this.groupingGrid1.Table.Records.FindRecord("Aachen"); Stefan


AD Administrator Syncfusion Team July 8, 2004 12:10 PM UTC

Thanks again for your help, Stefan. That all seems to work OK but I get an "Object reference not set to an instance of an object" exception...SOMETIMES. For speed, before I set the current record again I''ve use: TableModel.BeginUpdate(BeginUpdateOptions.None) // update code omitted for clarity - lots!!! TableModel.EndUpdate(false); Just before setting the current record I also call grid.Table.EnsureInitialized(grid); Do I need to call EnsureInitialized and if so what should I be passing into it - my grid? Help is very much appreciated Jason =========== Exception = Object reference not set to an instance of an object. StackTrace : at Syncfusion.Grouping.RecordsDetails.OnEnsureInitialized(Object sender) at Syncfusion.Grouping.Element.EnsureInitialized(Object sender, Boolean notifyParent) at Syncfusion.Grouping.Element.EnsureInitialized(Object sender, Boolean notifyParent) at Syncfusion.Grouping.RuntimeElementsInTableCollection.Contains(Element value) at Syncfusion.Windows.Forms.Grid.Grouping.GridTable.RepaintElementsInQueue() at Syncfusion.Windows.Forms.Grid.Grouping.GridTableControl.SynchronizeGridWithEngine() at Syncfusion.Windows.Forms.Grid.Grouping.GridTableControl.OnBeforePaint(EventArgs e) at Syncfusion.Windows.Forms.Grid.GridControlBase.WndProc(Message& msg) at Syncfusion.Windows.Forms.Grid.Grouping.GridTableControl.WndProc(Message& msg) at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) -----------------------------------------------------------------------


AD Administrator Syncfusion Team July 8, 2004 03:19 PM UTC

Jason, From looking at the call stack I think it''s the following line that causes the exception in RecordsDetails: protected override bool OnEnsureInitialized(object sender) { if (this.ParentTable.inItemDeleted) return false; I will add add a check for ParentTable != null there. The problem itsself occurs because the RepaintElementsInQueue method still has a list of elements to be painted that have been removed from the table. There is a method Table.ResetRepaintElementsInQueue that is internal for the current version. I will make that method public to make sure there is at least a workaround for the future in such cases. The grid should of course detect when elements are removed from the table and then also automatically removed them from the RepaintElementsInQueue queue. But until all scenarios are covered manually calling ResetRepaintElementsInQueue will let you avoid that issue. Stefan


AD Administrator Syncfusion Team July 12, 2004 09:07 AM UTC

Thanks for the info Stefan. Until you''ve had a chance to make ResetRepaintElementsInQueue public want would you suggest that I do for my application? This could be a major flaw on my application and could delay us from going live. When do you think you will have this version available Thanks Jason


AD Administrator Syncfusion Team July 13, 2004 04:36 PM UTC

Jason, we are working on a public patch for Suite that we expect to be out within a couple of weeks. But you can open a direct trac incident and we''ll send you private patch with that change. Stefan


AD Administrator Syncfusion Team July 26, 2004 09:55 AM UTC

Thanks for your help so far, I''m working with the patched version of the grid but would like to know the best place to call ResetRepaintElementsInQueue? I have a Builder object that takes various information and sets up the grid accordingly. Should it be done after setting the Datasource. Such as: syncGrid.SuspendLayout(); syncGrid.TableModel.BeginUpdate(Syncfusion.Windows.Forms.BeginUpdateOptions.None); try { if (syncGrid.TableModel.Table != null) { syncGrid.TableModel.Table.ResetRepaintElementsInQueue(); } } catch (Exception ex) { Logger.WriteLogEntry("Unlogged exception caught:" + ex.ToString()); } syncGrid.DataSource = null;// in case it helps!!! syncGrid.DataSource = dataSource; // Cache for a bit of speed GridTableDescriptor tableDescriptor = syncGrid.TableDescriptor; tableDescriptor.Columns.Clear();// Clear any columns that were auto-populated by grid by setting datasource tableDescriptor.VisibleColumns.Clear(); tableDescriptor.GroupedColumns.Clear(); tableDescriptor.SortedColumns.Clear(); // code omitted to set visible & grouped cols syncGrid.TableModel.EndUpdate(true); syncGrid.ResumeLayout(); Jason


AD Administrator Syncfusion Team July 28, 2004 06:59 PM UTC

With the next build I added some logic so that elements in RepaintElementsQueue will removed themselves from the list once they were disposed. That should fix your underlying problem. You can do it either before or after setting the datasource. It shouldn''t matter as long as there is no WndProc processed in the meantime or Control.Update was called. Stefan


AD Administrator Syncfusion Team July 29, 2004 08:51 AM UTC

Thanks Stefan, what date is the next build due? Are you saying that I should NOT explicitly call Update() - I''m not at the moment.


AD Administrator Syncfusion Team July 29, 2004 12:23 PM UTC

No, calling Update is fine. You can call it after you applied all your changes to the grid. The repaint elements queue should then be cleared before the update in your case. We plan starting testing a new public patch tomorrow and should have it ready next week. But we can send you the latest private build when you open a direct trac incident. Stefan

Loader.
Live Chat Icon For mobile
Up arrow icon