BindingManagerBase.Position and Table.Rows.Find

  • Thread starter Thread starter Christopher Weaver
  • Start date Start date
C

Christopher Weaver

How do I retrieve the position value after successfully finding the row that
I'm looking for? I need to set

BindingManagerBase.Position

so that all of the controls on the form are synchronized. Is there another
way of moving to a particular record within a dataset given the value of the
key?
 
Hi Christopher,

As you use complex data binding, do the following:

CurrencyManager cm = (CurrencyManager)this.BindingContext[theDataTable];
DataView dv = (DataView)cm.List;

// Search the row in the DataView by its key.
// We need the index of the row in the DataView, not the source DataTable.

cm.Position = foundRowIndex;
 
Here's what I've tried so far:

The declaration in the form's class definition:
private CurrencyManager ByNames_cMgr;

In the form constructor:
ByNames_cMgr = (CurrencyManager)this.BindingContext[dsAssignedBy1,
"Table"];

In the DropDown event handler for the ComboBox:

ComboBox cb = (ComboBox)sender;
DataTable dt = (DataTable)cb.DataSource;
string cbText = cb.Text;
int rowIndex;
try
{
try
{
Cursor.Current = Cursors.WaitCursor;
odbcDA_Names.Fill(dt);
DataView dv = new DataView(dt);
dv.Sort = "Name";
rowIndex = dv.Find(cbText);
MessageBox.Show(rowIndex.ToString());
ByNames_cMgr.Position = rowIndex;

etc....

The MessageBox.Show call confirms that I've actually found the index of the
row that I'm looking for, but the Position assignment doesn't move the
pointer within the ComboBox dropdown list to that record.

Any help you can give will be greatly appreciated.
 
Back
Top