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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Getting default DataView

Thread ID:

Created:

Updated:

Platform:

Replies:

10505 Feb 4,2004 08:47 AM UTC Feb 4,2004 10:02 AM UTC WinForms 1
loading
Tags: GridControl
Administrator [Syncfusion]
Asked On February 4, 2004 08:47 AM UTC

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

Administrator [Syncfusion]
Replied On 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();

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;