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

GDBG: Retrieve the RowIndex given the primary key of the underlying DataSource

Hi, Is it possible to get the RowIndex for the current GDBG sorting given a specific DataRow (or a primary key) of the underlying data source? Thanks in advance Kind Regards Wolfgang

2 Replies

AD Administrator Syncfusion Team June 8, 2006 10:08 AM UTC

Hi Wolfgang, If the data is sorted by primary key, you probably can use DataView.Find instead of just doing a linear search though the linear search is pretty efficient for simple look ups on small to medium sized tables. private int FindSortedValue(int val) { int found = -1; CurrencyManager cm = this.gridDataBoundGrid1.BindingContext[this.gridDataBoundGrid1.DataSource, this.gridDataBoundGrid1.DataMember] as CurrencyManager; if(cm != null) { DataView dv = cm.List as DataView; for(int i = 0; i < dv.Count; ++i) { if(dv[i][this.idCol].Equals(val)) { found = i; break; } } } return found; } //To get the RowIndex of the databound grid , you need to use this code. Here is a code snippet. this.gridDataBoundGrid1.Binder.PositionToRowIndex( FindSortedValue(int.Parse(this.textBox1.Text))) Here is a sample. http://www.syncfusion.com/Support/user/uploads/GDBG_UniqueID_8f986ed3.zip Let me know if this helps, Best Regards, Haneef


AD Administrator Syncfusion Team June 9, 2006 06:21 AM UTC

Hi Haneef, Thank you for your help. Using DataView.Find works fine for me. Regards Wolfgang

Loader.
Live Chat Icon For mobile
Up arrow icon