J
Jeff
I have a situation where I need to recursively position the CurrencyManager
of a DataRow's parent DataRow.
The problem is that the CurrencyManager.List contains DataRowView objects
that I want to find via IndexOf, but I when I GetParentRows... I get a
"DataRow". Any ideas on how I can get a DataRowView instead?
DataSet is Northwind... Customers, Orders, OrderDetails via 2 DataRelations.
The struct below just holds a DataRow and it's child relation navigation
path.
Try following the code below as if the UI caused the OrderDetails
CurrencyManager to change positions.
private void cm_PositionChanged(object sender, EventArgs e)
{
CurrencyManager cm = (CurrencyManager)sender;
String navPath;
if (cm.Position >= 0)
{
DataRowView drv = (DataRowView)((DataView)cm.List)[cm.Position];
DataRow dr = drv.Row;
if (dr.RowState != DataRowState.Detached)
{
ArrayList dataRows = new ArrayList();
dataRows.Add(new RowRelation("", dr)); // this is the DataRow
actually selected
while (dr.Table.ParentRelations.Count > 0)
{
navPath = dr.Table.ParentRelations[0].RelationName;
dr = dr.GetParentRow(dr.Table.ParentRelations[0]); //
this is the relative parent DataRow, what I really need the DataRowView of
the Parent
dataRows.Add(new RowRelation(navPath, dr));
}
navPath =
((RowRelation)dataRows[dataRows.Count-1]).DataRow.Table.TableName;
RowRelation rr;
for (int i = dataRows.Count; i>0; i--)
{
rr = (RowRelation)dataRows[i-1];
dr = rr.DataRow;
cm = (CurrencyManager)BindingContext[dr.Table.DataSet,
navPath];
navPath = navPath + "." + rr.NavigationPath;
// **** Here is where I need the DataRowView ****
//Console.WriteLine(cm.List.IndexOf(dr).ToString()); //
Always returns -1 becuase cm.List contains DataRowView's not DataRow's eh?
}
}
}
}
private struct RowRelation
{
public String NavigationPath;
public DataRow DataRow;
public RowRelation(String navigationPath, DataRow dataRow)
{
NavigationPath = navigationPath;
DataRow = dataRow;
}
}
of a DataRow's parent DataRow.
The problem is that the CurrencyManager.List contains DataRowView objects
that I want to find via IndexOf, but I when I GetParentRows... I get a
"DataRow". Any ideas on how I can get a DataRowView instead?
DataSet is Northwind... Customers, Orders, OrderDetails via 2 DataRelations.
The struct below just holds a DataRow and it's child relation navigation
path.
Try following the code below as if the UI caused the OrderDetails
CurrencyManager to change positions.
private void cm_PositionChanged(object sender, EventArgs e)
{
CurrencyManager cm = (CurrencyManager)sender;
String navPath;
if (cm.Position >= 0)
{
DataRowView drv = (DataRowView)((DataView)cm.List)[cm.Position];
DataRow dr = drv.Row;
if (dr.RowState != DataRowState.Detached)
{
ArrayList dataRows = new ArrayList();
dataRows.Add(new RowRelation("", dr)); // this is the DataRow
actually selected
while (dr.Table.ParentRelations.Count > 0)
{
navPath = dr.Table.ParentRelations[0].RelationName;
dr = dr.GetParentRow(dr.Table.ParentRelations[0]); //
this is the relative parent DataRow, what I really need the DataRowView of
the Parent
dataRows.Add(new RowRelation(navPath, dr));
}
navPath =
((RowRelation)dataRows[dataRows.Count-1]).DataRow.Table.TableName;
RowRelation rr;
for (int i = dataRows.Count; i>0; i--)
{
rr = (RowRelation)dataRows[i-1];
dr = rr.DataRow;
cm = (CurrencyManager)BindingContext[dr.Table.DataSet,
navPath];
navPath = navPath + "." + rr.NavigationPath;
// **** Here is where I need the DataRowView ****
//Console.WriteLine(cm.List.IndexOf(dr).ToString()); //
Always returns -1 becuase cm.List contains DataRowView's not DataRow's eh?
}
}
}
}
private struct RowRelation
{
public String NavigationPath;
public DataRow DataRow;
public RowRelation(String navigationPath, DataRow dataRow)
{
NavigationPath = navigationPath;
DataRow = dataRow;
}
}