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

Get corresponding DataRow for a grid row in hierarchical grid?

I have seen the topics for finding the DataRow for a corresponding grid row in the KB and Forums. http://www.syncfusion.com/Support/Forums/message.aspx?MessageID=14037 http://www.syncfusion.com/Support/article.aspx?id=10440 But...how can I get the DataRow for a child table in a hierarchical grid? I think I''m almost there, but can''t quite get it. It looks like the code from the above links gives me the DataRow for the correspdoning "parent" DataRow in the outer table. If the current selected cell is sitting on a row in the grid from a child table, I need to get that DataRow, not the parent one. CurrencyManager cm1 = (CurrencyManager)this.BindingContext[grid2.DataSource, "Categories"]; // outer table CurrencyManager cm2 = (CurrencyManager)this.BindingContext[grid2.DataSource, "Families"]; // inner table CurrencyManager cm3 = (CurrencyManager)this.BindingContext[grid2.DataSource, "Categories.Category_Family"]; // related table?! DataRow dr1 = ((DataRowView)cm1.Current).Row; DataRow dr2 = ((DataRowView)cm2.Current).Row; DataRow dr3 = ((DataRowView)cm3.Current).Row; Example: when on 2nd row of child records under the 2nd parent record, the above code gives: -- dr1 ends up as the parent table row. -- dr2 ends up as the first row of the child table under the first row of the parent table -- dr3 (based on the relation setup between the 2 tables) ends up as the first row of the child table under the second row of the parent table I''m not too familiar with BindingContext and CurrencyManager.Current -- should this "Current" property be in sync with what''s selected in the grid? Even in a hierarchical grid where, when sections are collapsed, grid rows are reordered/removed? I''ve looked at using RowIndexToListManagerPosition() but help docs say "Only the list manager position for the outer hierarchy is returned". Any thoughts?

3 Replies

AD Administrator Syncfusion Team June 16, 2004 02:48 PM UTC

In a hierarchical grid, it is simpler to use the GridBoundRecordState. Here is some code.
 
GridBoundRecordState rs = this.gridDataBoundGrid1.Binder.GetRecordStateAtRowIndex(gridRowIndex);
int pos = rs.Position;
CurrencyManager cm = rs.ListManager as CurrencyManager;
if(cm != null)
{
 DataView dv = cm.List as DataView;
 if(dv != null)
 {
  DataRow dr = dv[pos].Row;
  Console.WriteLine(dr[0].ToString() + "  " + dr[1].ToString());
 }
}


DA Dan June 16, 2004 08:39 PM UTC

Thanks Clay! That works great. Just curious, where would I have found this GetRecordStateAtRowIndex to CurrencyManager to List (DataView) information? I''m learning mostly from reading these forums, but wondering where there is more overall docs on this stuff? The user guide is pretty high level, and the help integrated into vs.net is basically a reference, so you kinda have to know what you''re looking for. Thanks.


AD Administrator Syncfusion Team June 16, 2004 10:44 PM UTC

We are working on better documentation. In general, for details and use cases, the samples are a good source of information. There are two samples that we ship that use GridBoundRecordState. It is a key object in hierarchical GridDataBoundGrids, and more information should be included in our User Guide and KB on this class.

Loader.
Live Chat Icon For mobile
Up arrow icon