M
Mike Edenfield
I have a series of user-bound controls that are associated with a
dataset, and need to be able to move the displayed data row in one
control based on events in another.
I have all of the controls bound to the same dataset on my form, and the
navigation controls are passing a complete DataRow object in the event
arguments. I know I need to get the CurrencyManager for the binding
context, and set it's Position, but it's not working properly.
The code I am currently using follows (Names have been changed to
protect the innocent . I have a strongly typed dataset called
"TypedDataSet" with a table called "Table" in it. The table has an "ID"
column which is the primary key. The data is being read into the
dataset from an XML document.
/**********/
TypedDataSet ds = _dataSet;
TypedDataSet.TableRow row = e.nodeData as TypedDataSet.TableRow;
int pos = ds.Table.DefaultView.Find(row.ID);
CurrencyManager cm = BindingContext[ds, "Table"] as CurrencyManager;
cm.Position = pos;
/**********/
When I run this code, the data-bound controls do move to a new row. But
it's always the wrong row. The problem appears to be that the DataView
has the rows sorted differently than the DataTable. I have tried
explicitly sorting by primary key (DefaultView.Sort = "ID ASC") as well
as using the default (DefaultView.ApplyDefaultSort = true), but the
results are identical.
The DataTable.Find() method doesn't appear to be useful, since that
returns a DataRow -- that I already have -- but I have no way to move
the CurrencyManager to a specific data row object, only to a specific
position.
I'm sure there's some .NET property or method I'm missing but I can't
seem to find it. Any ideas?
--Mike
's/not.//g' to email me.
dataset, and need to be able to move the displayed data row in one
control based on events in another.
I have all of the controls bound to the same dataset on my form, and the
navigation controls are passing a complete DataRow object in the event
arguments. I know I need to get the CurrencyManager for the binding
context, and set it's Position, but it's not working properly.
The code I am currently using follows (Names have been changed to
protect the innocent . I have a strongly typed dataset called
"TypedDataSet" with a table called "Table" in it. The table has an "ID"
column which is the primary key. The data is being read into the
dataset from an XML document.
/**********/
TypedDataSet ds = _dataSet;
TypedDataSet.TableRow row = e.nodeData as TypedDataSet.TableRow;
int pos = ds.Table.DefaultView.Find(row.ID);
CurrencyManager cm = BindingContext[ds, "Table"] as CurrencyManager;
cm.Position = pos;
/**********/
When I run this code, the data-bound controls do move to a new row. But
it's always the wrong row. The problem appears to be that the DataView
has the rows sorted differently than the DataTable. I have tried
explicitly sorting by primary key (DefaultView.Sort = "ID ASC") as well
as using the default (DefaultView.ApplyDefaultSort = true), but the
results are identical.
The DataTable.Find() method doesn't appear to be useful, since that
returns a DataRow -- that I already have -- but I have no way to move
the CurrencyManager to a specific data row object, only to a specific
position.
I'm sure there's some .NET property or method I'm missing but I can't
seem to find it. Any ideas?
--Mike
's/not.//g' to email me.