473,386 Members | 1,708 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

is there a way to change the key of an item within a collection?

dx
Is anyone aware of a way to change the key (string) within a collection . I
have a collection of items, when a 'new' item is added it has a temporary
key which is used until the collection is saved to the database. I'd like to
update the key to reflect the actual Id assigned by the db once saved.

The key is readonly when i access like this:

Me.Keys.Item(nIdx)

Thanks,
Stan

Nov 21 '05 #1
8 2436
"dx" <de*********@yahoo.com> schrieb:
Is anyone aware of a way to change the key (string) within a collection .
I have a collection of items, when a 'new' item is added it has a
temporary key which is used until the collection is saved to the database.
I'd like to update the key to reflect the actual Id assigned by the db
once saved.

The key is readonly when i access like this:

Me.Keys.Item(nIdx)

Remove the item and add it with the new key.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #2
dx

That does not work for me. That is why I asked about changing the Key
string.


"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
"dx" <de*********@yahoo.com> schrieb:
Is anyone aware of a way to change the key (string) within a collection .
I have a collection of items, when a 'new' item is added it has a
temporary key which is used until the collection is saved to the
database. I'd like to update the key to reflect the actual Id assigned by
the db once saved.

The key is readonly when i access like this:

Me.Keys.Item(nIdx)

Remove the item and add it with the new key.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #3
"dx" <de*********@yahoo.com> schrieb:
Is anyone aware of a way to change the key (string) within a collection .
I have a collection of items, when a 'new' item is added it has a
temporary key which is used until the collection is saved to the database.
I'd like to update the key to reflect the actual Id assigned by the db
once saved.

The key is readonly when i access like this:

Me.Keys.Item(nIdx)

Remove the item and add it with the new key.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #4
dx

That does not work for me. That is why I asked about changing the Key
string.


"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
"dx" <de*********@yahoo.com> schrieb:
Is anyone aware of a way to change the key (string) within a collection .
I have a collection of items, when a 'new' item is added it has a
temporary key which is used until the collection is saved to the
database. I'd like to update the key to reflect the actual Id assigned by
the db once saved.

The key is readonly when i access like this:

Me.Keys.Item(nIdx)

Remove the item and add it with the new key.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #5
"dx" <de*********@yahoo.com> schrieb:
That does not work for me. That is why I asked about changing the Key
string.


Huh?! What doesn't work with removing the item using its old key and
re-adding the object using its new key?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #6
"dx" <de*********@yahoo.com> schrieb:
That does not work for me. That is why I asked about changing the Key
string.


Huh?! What doesn't work with removing the item using its old key and
re-adding the object using its new key?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #7
Stan,
What I normally do is make the "key" read-only on the object being contained
which prevents this problem in the first place.

When I do have objects that the "key" can change, I normally have the object
being contained raise an event when the "key" changes. The collection
handles this event and does as Herfried suggests, removes the old key and
adds the new key, which may entail removing the object under the old key &
adding the object under the new key.

I do however favor immutable keys as its easier to maintain & program...

Hope this helps
Jay

"dx" <de*********@yahoo.com> wrote in message
news:9i****************@fe05.lga...
Is anyone aware of a way to change the key (string) within a collection .
I have a collection of items, when a 'new' item is added it has a
temporary key which is used until the collection is saved to the database.
I'd like to update the key to reflect the actual Id assigned by the db
once saved.

The key is readonly when i access like this:

Me.Keys.Item(nIdx)

Thanks,
Stan

Nov 21 '05 #8
Stan,
What I normally do is make the "key" read-only on the object being contained
which prevents this problem in the first place.

When I do have objects that the "key" can change, I normally have the object
being contained raise an event when the "key" changes. The collection
handles this event and does as Herfried suggests, removes the old key and
adds the new key, which may entail removing the object under the old key &
adding the object under the new key.

I do however favor immutable keys as its easier to maintain & program...

Hope this helps
Jay

"dx" <de*********@yahoo.com> wrote in message
news:9i****************@fe05.lga...
Is anyone aware of a way to change the key (string) within a collection .
I have a collection of items, when a 'new' item is added it has a
temporary key which is used until the collection is saved to the database.
I'd like to update the key to reflect the actual Id assigned by the db
once saved.

The key is readonly when i access like this:

Me.Keys.Item(nIdx)

Thanks,
Stan

Nov 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Sam Fisher | last post by:
Hi, I have a crystal reports hosted on the IIS as web service. Everything works fine except that I can not access the database other than the one on which the report originally created. I am...
1
by: Craig | last post by:
How do I programmatically change the text property of a label in an ItemTemplate in a datagrid? Specifically the Text property. I want to change the databinding to another column at runtime. ...
2
by: | last post by:
While I was learning about baking cookies in ASP.NET, I also ran across this interesting article that outlined a few bombs to watch out for when using cookies in ASP.NET: ...
9
by: Max Weebler | last post by:
Hi, I have a datagrid built that has an alternating item style that sets the backcolor and ForeColor of its rows. I have 4 template columns. One of them has a LinkButton embedded in it to...
0
by: dx | last post by:
Is anyone aware of a way to change the key (string) within a collection . I have a collection of items, when a 'new' item is added it has a temporary key which is used until the collection is saved...
6
by: moondaddy | last post by:
I'm writing a windows app in WPF and want to change the shape of a thumb to an ellipse. Is this possible? also, the edges of the thumb are beveled. Is it possible to change this to a flat look...
3
by: S_K | last post by:
Hi, I have a list of 6 DropDownList boxes, from DropDownList1 to DropDownList6, and I'm changing the SelectedIndex of each using a foreach loop as follows: foreach(PaymentReqDisplay...
21
by: bilgekhan | last post by:
After doing a succcessful insert() or find() on a set<Tcontainer is it possible to get the item number of this item in the set? (ie. its zero-based sequence number (position/location/rank/index)...
7
by: colin | last post by:
Hi, I have my property editor wich uses the pop up collection editor for arrays etc, but i have had to use a generic wrapper for the elements in some types of collections. although the editing...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.