CurrencyManager Relations

C

Christopher Weaver

I have a CM bound to a table like this:
cMgrSort = (CurrencyManager)this.BindingContext[dsSortOrders,
"SortOrder"];
Under certain circumstances I need to find a specific row in that table
DataRow r = dsSortOrders.Tables["SortOrder"].Rows.Find(SortOrder);
When that happens, I need the CM.Position to reflect that row so that
everything stays in sync. How can I ensure that this happens?
 
N

Nicholas Paldino [.NET/C# MVP]

Christopher,

Once you find the row, you will have to set the Position property on the
CurrencyManager instance to reflect the position in the list that the row is
at. Once you do this, everything will be in sync.

Hope this helps.
 
C

Christopher Weaver

Exactly, but how do I do it! The problem boils down to my not knowing how
to find the position of the row in the list.


Nicholas Paldino said:
Christopher,

Once you find the row, you will have to set the Position property on
the CurrencyManager instance to reflect the position in the list that the
row is at. Once you do this, everything will be in sync.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Christopher Weaver said:
I have a CM bound to a table like this:
cMgrSort = (CurrencyManager)this.BindingContext[dsSortOrders,
"SortOrder"];
Under certain circumstances I need to find a specific row in that table
DataRow r = dsSortOrders.Tables["SortOrder"].Rows.Find(SortOrder);
When that happens, I need the CM.Position to reflect that row so that
everything stays in sync. How can I ensure that this happens?
 
N

Nicholas Paldino [.NET/C# MVP]

Christoper,

That requires some specific knowledge of the data you are looking at
(which I am sure you have). Basically, you have to take the field values
which make the row unique (usually, a primary key), and search for it in
your sorted data list.

If you are looking at a DataTable, or a DataView, you can use the
indexer, from 0 to Count - 1 to cycle through the rows and determine if the
row matches your found row. If your data source is sorted by this key, then
you could even do a binary search to find the index of the row.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Christopher Weaver said:
Exactly, but how do I do it! The problem boils down to my not knowing how
to find the position of the row in the list.


Nicholas Paldino said:
Christopher,

Once you find the row, you will have to set the Position property on
the CurrencyManager instance to reflect the position in the list that the
row is at. Once you do this, everything will be in sync.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Christopher Weaver said:
I have a CM bound to a table like this:
cMgrSort = (CurrencyManager)this.BindingContext[dsSortOrders,
"SortOrder"];
Under certain circumstances I need to find a specific row in that table
DataRow r = dsSortOrders.Tables["SortOrder"].Rows.Find(SortOrder);
When that happens, I need the CM.Position to reflect that row so that
everything stays in sync. How can I ensure that this happens?
 
C

Christopher Weaver

"cycle through the rows "

So I take it there is no property or function that will return the "IndexOf"
for a given primary key field value. But I guess I could write a genic one,
something like int FindKey(int KeyValue, DataTable.Rows r){}. Fortunately,
in this particular case, there are relatively few rows of data in this
DataTable.

Thanks for your help.


Nicholas Paldino said:
Christoper,

That requires some specific knowledge of the data you are looking at
(which I am sure you have). Basically, you have to take the field values
which make the row unique (usually, a primary key), and search for it in
your sorted data list.

If you are looking at a DataTable, or a DataView, you can use the
indexer, from 0 to Count - 1 to cycle through the rows and determine if
the row matches your found row. If your data source is sorted by this
key, then you could even do a binary search to find the index of the row.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Christopher Weaver said:
Exactly, but how do I do it! The problem boils down to my not knowing
how to find the position of the row in the list.


Nicholas Paldino said:
Christopher,

Once you find the row, you will have to set the Position property on
the CurrencyManager instance to reflect the position in the list that
the row is at. Once you do this, everything will be in sync.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I have a CM bound to a table like this:
cMgrSort = (CurrencyManager)this.BindingContext[dsSortOrders,
"SortOrder"];
Under certain circumstances I need to find a specific row in that table
DataRow r = dsSortOrders.Tables["SortOrder"].Rows.Find(SortOrder);
When that happens, I need the CM.Position to reflect that row so that
everything stays in sync. How can I ensure that this happens?
 
C

Christopher Weaver

Oooops!

Should have been
int FindKey(int Key, System.Data.DataRowCollection r)


Christopher Weaver said:
"cycle through the rows "

So I take it there is no property or function that will return the
"IndexOf" for a given primary key field value. But I guess I could write
a genic one, something like int FindKey(int KeyValue, DataTable.Rows r){}.
Fortunately, in this particular case, there are relatively few rows of
data in this DataTable.

Thanks for your help.


Nicholas Paldino said:
Christoper,

That requires some specific knowledge of the data you are looking at
(which I am sure you have). Basically, you have to take the field values
which make the row unique (usually, a primary key), and search for it in
your sorted data list.

If you are looking at a DataTable, or a DataView, you can use the
indexer, from 0 to Count - 1 to cycle through the rows and determine if
the row matches your found row. If your data source is sorted by this
key, then you could even do a binary search to find the index of the row.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Christopher Weaver said:
Exactly, but how do I do it! The problem boils down to my not knowing
how to find the position of the row in the list.


in message Christopher,

Once you find the row, you will have to set the Position property on
the CurrencyManager instance to reflect the position in the list that
the row is at. Once you do this, everything will be in sync.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

I have a CM bound to a table like this:
cMgrSort = (CurrencyManager)this.BindingContext[dsSortOrders,
"SortOrder"];
Under certain circumstances I need to find a specific row in that
table
DataRow r = dsSortOrders.Tables["SortOrder"].Rows.Find(SortOrder);
When that happens, I need the CM.Position to reflect that row so that
everything stays in sync. How can I ensure that this happens?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top