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

Getting default DataView

Lets say I have CatsAndDogsTable bound to a datagrid which is sorted by one of its columns. I am using this code to get the selected row in an underlying datatable where i is the row clicked on. DataView dv = CatsAndDogsTable.DefaultView; DataRowView dvr = dv[i-1]; DataRow row = dvr.Row; string id = row["id"]; This works just fine, but i was wondering if defaultview is goign to always be the datagrid''s view. after all this property is on the table and not the grid. will this approach work if i am using a datatable being displayed in two grids at the same time, or in two different forms. very few of the SF examples have DataView in them. i know i can get cell values by index with grid[x, y] but i really want to get the row value from the underlying datasource using grid[y]. however this doesnt exist and dataview was my next best guess. is thre a diffent/more consistent way of getting this value. i just dotn like relying on a propery called ''default view''. if it aint broke dont fix it - sure. i just wanted to understand this procss a little better for future reference. thakns -simon

1 Reply

AD Administrator Syncfusion Team February 4, 2004 10:02 AM UTC

You can get at the object in the grid row through the CurrencyManager. CurrencyManager cm; cm = this.BindingContext[grid.DataSource. grid.DataMember] as CurrencyManager; int position = grid.Binder.RowIndexToPosition(rowIndex); DataRowView drv; drv = cm.List[position] as DataRowView; This should work when the grid''s DataSource is a DataTable. You do not need to use the defaultview. If you bind the same table to two grids, you would want to use two different bindingcontexts unless you want the current position in both grid to always be in sync. To make sure a grid has a different bindingcontext, you can use grid.BindingContext = new BindingContext();

Loader.
Live Chat Icon For mobile
Up arrow icon